folium地图中的Colormap问题

问题描述 投票:-1回答:1

我想根据COVID 19案例的数据创建一个美国的热图。为此,我使用了 folium 和 geopandas。下面是 数据链接

和我使用的代码如下。

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参数造成的。

python data-visualization geojson colormap folium
1个回答
1
投票

似乎你应该写 name 大写 NAMEfields=['Name','cases'] 因为在错误信息中可用的字段为 NAME、STATE、case

© www.soinside.com 2019 - 2024. All rights reserved.