下面是URL的示例:https://plotly.com/python/choropleth-maps/#base-map-configuration(按GeoJSON属性编制索引)。这是我的代码:
厄瓜多尔的数据框架:
Provinces Confirmed cases Confirmed deaths Probable deaths
0 AZUAY 10688.0 195.0 12.0
1 BOLÍVAR 2115.0 66.0 12.0
2 CAÑAR 2153.0 83.0 7.0
3 CARCHI 3058.0 104.0 1.0
4 CHIMBORAZO 2536.0 315.0 119.0
map_ecuador = folium.Map(location=[-1.3397668, -79.3666965.], tiles='OpenStreetMap', zoom_start=7)
geoURL="https://data.humdata.org/dataset/e66dbc70-17fe-4230-b9d6-855d192fc05c/resource/6fa37b41-ad28-40a6-9641-3b4efd4dbe13/download/ecuador.geojson"
with urlopen(geoURL) as response:
geojson = json.load(response)
print(ecuador["Provinces"][0])
print(geojson["features"][0]["properties"])
results:
AZUAY
{'DPA_VALOR': 0, 'DPA_ANIO': '2011', 'DPA_CANTON': '0101', 'DPA_DESCAN': 'CUENCA', 'DPA_PROVIN':
'01', 'DPA_DESPRO': 'AZUAY', 'PCODE2': 'EC0101'}
fig = px.choropleth(ecuador, geojson=geojson, color="Bergeron",
locations=ecuador['Provinces'],
featureidkey="features.properties",
projection="mercator"
)
fig.update_geos(fitbounds="locations", visible=False)
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()
然后,我得到了这个错误:
TypeError Traceback (most recent call last)
<ipython-input-68-7439eb1d4543> in <module>()
2 locations=ecuador['Provinces'],
3 featureidkey="features.properties",
----> 4 projection="mercator"
5 )
6 fig.update_geos(fitbounds="locations", visible=False)
TypeError: choropleth() got an unexpected keyword argument 'geojson'
请帮我检查一下我正在遵循的指南。我认为我的问题在于featureidkey,但如果没有它,地图不会绘制每个省份的多边形
该错误消息告诉您问题出在哪里:您正在传递一个
geojson
参数,这是它不期望的。您使用的plotly版本是什么?在v4.5.0中geojson
属性被添加到了px.choropleth
。我怀疑你使用的是旧版本https://github.com/plotly/plotly.py/blob/master/CHANGELOG.md#450 -2020-01-22
相关问题 更多 >
编程相关推荐