目前正在尝试学习cloropleth
问题:我目前正在使用一个密歇根州县的GeoJSON文件,并试图绘制一个州地图,显示选择约翰的人的百分比。但作为回报,我只得到了一张空空的无色美国地图,上面有一个传说。就像这样:

完整数据集:https://pastebin.com/x52E0Wii
我的GeoJSON文件可以在这里找到:https://gis-michigan.opendata.arcgis.com/datasets/67a8ff23b5f54f15b7133b8c30981441/explore?location=44.847247%2C-86.594000%2C7.73
我正在使用的代码:
fig = px.choropleth(statistical_data,
locations = 'NAME',
locationmode = 'ISO-3',
geojson = michigan_counties,
color = '%John',
featureidkey = 'properties.NAME')
fig.show()我以为会有一张密西根州县的地图,上面写着选择约翰的人的百分比。
发布于 2022-10-28 04:14:21
用户数据与geojosn之间的关联是不正确的。在您的数据示例中,Maker (而不是fips )是县名,因此将名称与geojson属性关联起来。此外,在这种情况下,您不需要设置位置模式。由于您显示了3个用户数据,因此附加的图像仅显示3个区域。也是geojosn的数据,但是我不能正确地得到它,所以我在引用中使用了geosjon。请确保使用的geojson属性具有名称字段。
from urllib.request import urlopen
import json
with urlopen('https://raw.githubusercontent.com/plotly/datasets/master/geojson-counties-fips.json') as response:
counties = json.load(response)
import plotly.express as px
fig = px.choropleth(statistical_data,
locations = 'NAME',
geojson = counties,
color = '%John',
featureidkey = 'properties.NAME',
scope='usa')
fig.update_geos(fitbounds="locations", visible=False)
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()

https://stackoverflow.com/questions/74230256
复制相似问题