如何解决如何用folium聚类圆形标记?
一些标记放置得很近,墨尔本有 4 个标记,放大时可见,我想在缩小时有一个带有计数的聚集标记。那可能吗? 请参阅下面的代码、数据框和我的输出。
我的输出:
墨尔本特写:
import pandas as pd
world_geo = r'world_countries.json' # geojson file
world_map = folium.Map(
location = [0,0],zoom_start = 3,width = 1500,height = 1100,tiles = 'cartodb positron',prefer_canvas = True,max_bounds = True
)
world_map.choropleth(
name = 'choropleth WB100',geo_data = world_geo,data = dfcv,columns = ['Country','Total'],key_on = 'feature.properties.name',nan_fill_color = 'white',nan_fill_opacity = 0.1,fill_color = 'Greens',fill_opacity = 0.7,line_opacity = 0.2,legend_name = 'Worlds Best 100 Bars'
)
world_map
mapa = folium.map.FeatureGroup()
for lat,lng,bar,city,pos in zip(
df.Latitude,df.Longitude,df.Bar,df.City,df.wb_pos):
label= '{},{},Number {}'.format(bar,pos)
mapa.add_child(
folium.CircleMarker(
[lat,lng],label = label,popup = label,radius = 5,color = 'yellow',fill = True,fill_color = 'blue',fill_opacity = 0.6
).add_to(mapa)
)
# Build a CircleMarker for each row based on the lat long of the record
df.apply(lambda row: folium.CircleMarker(
location=[row["Latitude"],row["Longitude"]],radius=10,).add_to(world_map),axis=1)
world_map.add_child(mapa)
请参阅下面的 df 数据框:
{'Bar': {0: 'Connaught Bar',1: 'dante',2: 'The Clumsies',3: 'Atlas',4: 'Tayēr + Elementary'},'City': {0: 'London',1: 'New York',2: 'athens',3: 'Singapore',4: 'London'},'Country': {0: 'UK',1: 'USA',2: 'Greece',4: 'UK'},'Delivery': {0: 0,1: 1,2: 1,3: 1,4: 1},'Latitude': {0: 51.507358,1: 40.7129,2: 37.9838,3: 1.352,4: 23.7276},'Longitude': {0: 0.1278,1: -74.006,2: 23.7275,3: 103.8198,4: 0.1278},'Region': {0: 'Europe',1: 'north America',2: 'Europe',3: 'Asia',4: 'Europe'},'Shop': {0: 1,2: 0,'Takeway': {0: 0,3: 0,'Virtual Events': {0: 0,1: 0,4: 0},'first_submission': {0: 0,'wb_pos': {0: 1,1: 2,2: 3,3: 4,4: 5}}
可能不相关,但为了避免混淆,请参阅下面的 dfcv 数据框:
{'Country': {0: 'United Kingdom',1: 'United States of America',2: 'Singapore',3: 'Australia',4: 'China'},'Total': {0: 13,1: 12,2: 7,3: 7,4: 6}}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。