(按 GeoJson 属性编制索引)如何使用正确的 featureidkey 绘制等值线?

(Indexing by GeoJson Properties ) How to plotted a choropleth using correctly 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() got an unexpected keyword argument 'geojson'

该错误消息告诉您问题所在:您正在传递一个 geojson 参数,这是它不期望的。您使用的是什么版本的 plotly? geojson 属性已添加到 v4.5.0 中的 px.choropleth。我怀疑您使用的是旧版本。

https://github.com/plotly/plotly.py/blob/master/CHANGELOG.md#450---2020-01-22