问题
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