plotly.express choropleth 只显示来自 geojson 的一些信息 [英] plotly.express choropleth only showing some information from geojson

查看:54
本文介绍了plotly.express choropleth 只显示来自 geojson 的一些信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 plotly.express 创建一个区域分布图,当图形加载时,它只显示一种颜色(色标的底部)并显示单个区域的轮廓.这显然意味着它正在读取 geojson 但没有正确显示.

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.

我的 df 看起来像这样:

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

我的代码是:

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.

图形输出:

推荐答案

我怀疑您遇到了绕组"问题GeoJSON 中的多边形:https://github.com/plotly/plotly.py/issues/2354#issuecomment-638742767

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

这篇关于plotly.express choropleth 只显示来自 geojson 的一些信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆