python - (按 GeoJson 属性进行索引)如何使用正确的 featureidkey 绘制等值线?
问题描述
我正在关注 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 上,但是没有它,地图就不会绘制每个省份的多边形。
解决方案
TypeError:choropleth() 得到了一个意外的关键字参数“geojson”
该错误消息告诉您问题所在:您传入了一个geojson
参数,这是它不期望的。你用的是什么版本的情节?在 v4.5.0geojson
中添加了该属性。px.choropleth
我怀疑您使用的是旧版本。
https://github.com/plotly/plotly.py/blob/master/CHANGELOG.md#450---2020-01-22
推荐阅读
- node.js - 在 mongodb 上保存信息的问题
- arrays - 如何将对象推入数组?在角 7
- gevent - 如何使gevent sleep精确?
- unity3d - 在 Mac 上制作 Windows 游戏并统一发布到 gamejolt,当有许多其他文件和文件夹时,我该怎么做才能发布文件?
- azure-webjobs - 连续网络作业与为计划运行触发
- javascript - Laravel 的 Controller.php 中的输入数字错误
- reactjs - 如何在按钮单击时创建元素?
- postgresql - PostgreSQL - 创建外部表时如何导入自定义数据类型(使用 postgres-fdw)?
- node.js - MongoDB 的正确结构
- mysql - 获取日期的 SQL 查询