【发布时间】:2020-09-16 17:37:04
【问题描述】:
我希望根据 COVID 19 病例的数据创建美国的热图。为此,我正在使用 folium 和 geopandas。这是link for the data
我使用的代码如下。
colormap = cm.linear.YlGnBu_09.to_step(data=merged_data_cases['cases'],
method='quant', quantiles=[0,0.1,0.75,0.9,0.98,1]
usa_map = folium.Map(location=[48, -102], zoom_start=3, tiles=None)
folium.TileLayer('CartoDB positron',name="Light Map",control=False).add_to(usa_map)
colormap.caption = 'Confirmed Cases'
style_function = lambda x: {"weight":0.5,
'color':'black',
'fillColor':colormap(x['properties']['cases']),
'fillOpacity':0.75}
highlight_function = lambda x: {'fillColor': '#000000',
'color':'#000000',
'fillOpacity': 0.50,
'weight': 0.1}
interactive = folium.features.GeoJson(
merged_data_cases,
style_function=style_function,
control=False,
highlight_function=highlight_function,
tooltip=folium.features.GeoJsonTooltip(
fields=['Name','cases'],
aliases=['State: ','Confirmed Cases: '],
style=("background-color: white; color: #333333; font-family: arial; font-size: 12px; padding: 10px;"),
sticky = True
)
)
colormap.add_to(usa_map)
usa_map.add_child(interactive)
usa_map
当我运行代码时,我收到以下错误。
AssertionError: The field Name is not available in the data. Choose from: ('NAME', 'STATE', 'cases').
我浏览了很多文章、博客和文档,但仍然无法找出我的错误。谁能指出我在这里做错了什么?我相信错误是由于 style_function 参数造成的。
【问题讨论】:
-
请提供完整的代码和数据。谢谢。
-
嗨,@sentence 我已经编辑了问题。
-
请不要发布代码和数据的图像。以可重复使用的格式(文本和文件)提供它们。谢谢。
-
对此我深表歉意。我提供了数据链接并删除了图片。
标签: python python-3.x geojson colormap folium