plotly.express choropleth only showing some information from geojson

只谈情不闲聊 提交于 2020-07-08 00:44:55

问题


I am trying to create a choropleth map using plotly.express When the figure loads it only shows one color (bottom of the color scale) and shows the outline of a singular region. This clearly means it is reading the geojson but not displaying properly.

My df looks as such:

     NUTS level nuts318cd  ...  2016.0    2017
 5        NUTS3     UKC11  ...  4457.0  4569.0
 6        NUTS3     UKC12  ...  4092.0  4137.0
 7        NUTS3     UKC13  ...  1692.0  1697.0
 8        NUTS3     UKC14  ...  7913.0  8088.0
 10       NUTS3     UKC21  ...  5872.0  6015.0
 ..         ...       ...  ...     ...     ...
 230      NUTS3     UKN12  ...  2256.0  2310.0
 231      NUTS3     UKN13  ...  2263.0  2287.0
 232      NUTS3     UKN14  ...  2555.0  2578.0

and my code is:

import plotly.express as px

fig = px.choropleth(data_frame=df, geojson=spatial, locations='nuts318cd',
                       featureidkey='properties.nuts318cd', color='2017',
                       scope='europe'
                   )
fig.update_geos(showcountries=False, showcoastlines=True,
                showland=False, fitbounds="locations")
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()

All data for this project is freely avaliable to reproduce if needed.

If anyone understand, help would be appreciated.

Graph output:


回答1:


I suspect you're hitting an issue with the "winding" of the polygons in your GeoJSON: https://github.com/plotly/plotly.py/issues/2354#issuecomment-638742767



来源:https://stackoverflow.com/questions/61966708/plotly-express-choropleth-only-showing-some-information-from-geojson

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!