在 folium 地图上绘制数据框中的纬度经度点 - iPython
plot Latitude longitude points from dataframe on folium map - iPython
我有一个数据框 lat/lon 坐标
latlon
(51.249443914705175, -0.13878830247011467)
(51.249443914705175, -0.13878830247011467)
(51.249768239976866, -2.8610415615063034)
...
我想将这些绘制到 Folium 地图上,但我不确定如何遍历每一行。
任何帮助将不胜感激,提前致谢!
这可以解决您的问题
import folium
mapit = None
latlon = [ (51.249443914705175, -0.13878830247011467), (51.249443914705175, -0.13878830247011467), (51.249768239976866, -2.8610415615063034)]
for coord in latlon:
mapit = folium.Map( location=[ coord[0], coord[1] ] )
mapit.save( 'map.html')
编辑(使用标记)
import folium
latlon = [ (51.249443914705175, -0.13878830247011467), (51.249443914705175, -0.13878830247011467), (51.249768239976866, -2.8610415615063034)]
mapit = folium.Map( location=[52.667989, -1.464582], zoom_start=6 )
for coord in latlon:
folium.Marker( location=[ coord[0], coord[1] ], fill_color='#43d9de', radius=8 ).add_to( mapit )
mapit.save( 'map.html')
如果你使用这个参考就太好了:https://github.com/python-visualization/folium
下面是我的做法,我实际上是在尝试整理一个示例笔记本(添加颜色、弹出窗口等)。我仍在解决问题,但您可以在这里找到它:
https://github.com/collinreinking/longitude_latitude_dot_plots_in_python_with_folium
import folium
import pandas as pd
#create a map
this_map = folium.Map(prefer_canvas=True)
def plotDot(point):
'''input: series that contains a numeric named latitude and a numeric named longitude
this function creates a CircleMarker and adds it to your this_map'''
folium.CircleMarker(location=[point.latitude, point.longitude],
radius=2,
weight=5).add_to(this_map)
#use df.apply(,axis=1) to "iterate" through every row in your dataframe
data.apply(plotDot, axis = 1)
#Set the zoom to the maximum possible
this_map.fit_bounds(this_map.get_bounds())
#Save the map to an HTML file
this_map.save('html_map_output/simple_dot_plot.html')
this_map
我有一个数据框 lat/lon 坐标
latlon
(51.249443914705175, -0.13878830247011467)
(51.249443914705175, -0.13878830247011467)
(51.249768239976866, -2.8610415615063034)
...
我想将这些绘制到 Folium 地图上,但我不确定如何遍历每一行。
任何帮助将不胜感激,提前致谢!
这可以解决您的问题
import folium
mapit = None
latlon = [ (51.249443914705175, -0.13878830247011467), (51.249443914705175, -0.13878830247011467), (51.249768239976866, -2.8610415615063034)]
for coord in latlon:
mapit = folium.Map( location=[ coord[0], coord[1] ] )
mapit.save( 'map.html')
编辑(使用标记)
import folium
latlon = [ (51.249443914705175, -0.13878830247011467), (51.249443914705175, -0.13878830247011467), (51.249768239976866, -2.8610415615063034)]
mapit = folium.Map( location=[52.667989, -1.464582], zoom_start=6 )
for coord in latlon:
folium.Marker( location=[ coord[0], coord[1] ], fill_color='#43d9de', radius=8 ).add_to( mapit )
mapit.save( 'map.html')
如果你使用这个参考就太好了:https://github.com/python-visualization/folium
下面是我的做法,我实际上是在尝试整理一个示例笔记本(添加颜色、弹出窗口等)。我仍在解决问题,但您可以在这里找到它:
https://github.com/collinreinking/longitude_latitude_dot_plots_in_python_with_folium
import folium
import pandas as pd
#create a map
this_map = folium.Map(prefer_canvas=True)
def plotDot(point):
'''input: series that contains a numeric named latitude and a numeric named longitude
this function creates a CircleMarker and adds it to your this_map'''
folium.CircleMarker(location=[point.latitude, point.longitude],
radius=2,
weight=5).add_to(this_map)
#use df.apply(,axis=1) to "iterate" through every row in your dataframe
data.apply(plotDot, axis = 1)
#Set the zoom to the maximum possible
this_map.fit_bounds(this_map.get_bounds())
#Save the map to an HTML file
this_map.save('html_map_output/simple_dot_plot.html')
this_map