我如何在 Folium 中实现这一点?
How do I achieve this in Folium?
我正在使用 Folium 绘制大地震图。我能够绘制所有实例,其中大约 25000 个。但是地图开始看起来很笨拙。我使用了以下代码:
map1 = folium.Map(location=[80., -180], zoom_start=1)
def color(magnitude):
if magnitude<6:
col='green'
elif [(magnitude>6)&(magnitude<7.5)]:
col='yellow'
else:
col='red'
return col
fg=folium.FeatureGroup(name="Earthquake Locations")
for latitude,longitude,magnitude in zip(earthquakes['Latitude'][:30],earthquakes['Longitude'][:30],earthquakes['Magnitude'][:30]):
fg.add_child(folium.Marker(location=[latitude,longitude],popup=(folium.Popup(magnitude)),icon=folium.Icon(color=color(magnitude))))
map1.add_child(fg)
现在我想让情节看起来像以下 R 笔记本中的第一个情节:
Notebook.
谁能帮我实现这样一个情节,其中各个点聚集在一起,当我们缩放时,这些点就会显示出来。
谢谢
是的,你可以。 MarkerCluster
就是你想要的
试一试
import folium
from folium.plugins import MarkerCluster
map1 = folium.Map(location=[80., -180], zoom_start=1)
def color(magnitude):
if magnitude<6:
col='green'
elif [(magnitude>6)&(magnitude<7.5)]:
col='yellow'
else:
col='red'
return col
map1.add_child(MarkerCluster(locations=list(zip(earthquakes['Latitude'],
earthquakes['Longitude'])),
popups=earthquakes['Magnitude'].astype(str),
icons=[color(m) for m in earthquakes['Magnitude']]))
map1
Bob Haffer 的代码也有效。我试图调整并写了另一段代码:
import folium
import folium.plugins
map1 = folium.Map(width=1000,height=500,location=[80, -180],tiles='CartoDB dark_matter',zoom_start=1)
def color(magnitude):
if magnitude<6:
col='green'
else:
col='red'
return col
marker_cluster = folium.plugins.MarkerCluster().add_to(map1)
for point in locationlist.index:
folium.Marker(list(locationlist.loc[point].values),popup='Magnitude:'+str(locationlist_pop[point]),icon=folium.Icon(color=color(locationlist_pop[point]))).add_to(marker_cluster)
marker_cluster = folium.plugins.MarkerCluster().add_to(map1)
map1
我正在使用 Folium 绘制大地震图。我能够绘制所有实例,其中大约 25000 个。但是地图开始看起来很笨拙。我使用了以下代码:
map1 = folium.Map(location=[80., -180], zoom_start=1)
def color(magnitude):
if magnitude<6:
col='green'
elif [(magnitude>6)&(magnitude<7.5)]:
col='yellow'
else:
col='red'
return col
fg=folium.FeatureGroup(name="Earthquake Locations")
for latitude,longitude,magnitude in zip(earthquakes['Latitude'][:30],earthquakes['Longitude'][:30],earthquakes['Magnitude'][:30]):
fg.add_child(folium.Marker(location=[latitude,longitude],popup=(folium.Popup(magnitude)),icon=folium.Icon(color=color(magnitude))))
map1.add_child(fg)
现在我想让情节看起来像以下 R 笔记本中的第一个情节: Notebook.
谁能帮我实现这样一个情节,其中各个点聚集在一起,当我们缩放时,这些点就会显示出来。
谢谢
是的,你可以。 MarkerCluster
就是你想要的
试一试
import folium
from folium.plugins import MarkerCluster
map1 = folium.Map(location=[80., -180], zoom_start=1)
def color(magnitude):
if magnitude<6:
col='green'
elif [(magnitude>6)&(magnitude<7.5)]:
col='yellow'
else:
col='red'
return col
map1.add_child(MarkerCluster(locations=list(zip(earthquakes['Latitude'],
earthquakes['Longitude'])),
popups=earthquakes['Magnitude'].astype(str),
icons=[color(m) for m in earthquakes['Magnitude']]))
map1
Bob Haffer 的代码也有效。我试图调整并写了另一段代码:
import folium
import folium.plugins
map1 = folium.Map(width=1000,height=500,location=[80, -180],tiles='CartoDB dark_matter',zoom_start=1)
def color(magnitude):
if magnitude<6:
col='green'
else:
col='red'
return col
marker_cluster = folium.plugins.MarkerCluster().add_to(map1)
for point in locationlist.index:
folium.Marker(list(locationlist.loc[point].values),popup='Magnitude:'+str(locationlist_pop[point]),icon=folium.Icon(color=color(locationlist_pop[point]))).add_to(marker_cluster)
marker_cluster = folium.plugins.MarkerCluster().add_to(map1)
map1