2017-10-17 98 views
0

我正在使用Folium繪製主要的地震圖。我能夠繪製所有實例,其中約25000個實例。但地圖開始顯得非常笨拙。我用下面的代碼:我如何在Folium中實現這一點?

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

有人可以幫助我實現這樣一個情節,在個人點聚集,當我們縮放,點出現。

謝謝

回答

1

是的,你可以。 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 

enter image description here

+0

它的工作..!謝謝 – user517696

+0

對,很好 –

1

由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 

Output

相關問題