Python Plotly.express choropleth仅显示一种颜色

Python Plotly.express choropleth仅显示一种颜色,python,pandas,plotly,choropleth,Python,Pandas,Plotly,Choropleth,我正在尝试使用plotly.express创建choropleth。图形可以加载,但它只显示一种颜色。我可以将鼠标移到每个功能上,它会显示相关信息,但不会以可变颜色显示。这意味着它正在读取geojson,但没有正确显示,但由于声誉不好,我无法联系他们或发表评论 以下是我的“预测”df: 我正在尝试将DataFrame与geojson文件中的属性匹配: #Read in geojson import geopandas as gpd import json hucs = gpd.read_fi

我正在尝试使用
plotly.express
创建choropleth。图形可以加载,但它只显示一种颜色。我可以将鼠标移到每个功能上,它会显示相关信息,但不会以可变颜色显示。这意味着它正在读取geojson,但没有正确显示,但由于声誉不好,我无法联系他们或发表评论

以下是我的“预测”df:

我正在尝试将DataFrame与geojson文件中的属性匹配:

#Read in geojson
import geopandas as gpd
import json


hucs = gpd.read_file(~/"HUC.geojson")

#Populate hucs['properties'] (i.e. convert to plotly-readible geojson-type)
hucs = json.loads(hucs.to_json())

#Print Properties for sanity check
print(hucs['features'][0]['properties'])
下面是输出显示的内容。请注意,鼠标悬停显示相关信息:


我的geojson和csv可供下载。

在打印之前,必须解开geojson:

#Read in geojson
import geopandas as gpd
import json


hucs = gpd.read_file(~/"HUC.geojson")

#Populate hucs['properties'] (i.e. convert to plotly-readible geojson-type)
hucs = json.loads(hucs.to_json())

看 及

#Read in geojson
import geopandas as gpd
import json


hucs = gpd.read_file(~/"HUC.geojson")

#Populate hucs['properties'] (i.e. convert to plotly-readible geojson-type)
hucs = json.loads(hucs.to_json())

#Print Properties for sanity check
print(hucs['features'][0]['properties'])
#...<a bunch of stuff we don't care about> 
{'huc12':170102120304}
#...
fig = px.choropleth(predictions,
                    geojson=hucs, color='Predicted PRBT',
                    locations='huc12', featureidkey='properties.huc12',
                    color_continuous_scale="Viridis", labels={'Predicted PRBT':'Predicted % RBT'})
fig.update_geos(fitbounds="locations",visible=False)
fig.show()
#Read in geojson
import geopandas as gpd
import json


hucs = gpd.read_file(~/"HUC.geojson")

#Populate hucs['properties'] (i.e. convert to plotly-readible geojson-type)
hucs = json.loads(hucs.to_json())

from geojson_rewind import rewind
hucs_rewound = rewind(hucs,rfc7946=False)


fig = px.choropleth(predictions,
                    geojson=hucs_rewound, color='Predicted PRBT',
                    locations='huc12', featureidkey='properties.huc12',
                    color_continuous_scale="Viridis", labels={'Predicted PRBT':'Predicted % RBT'})
fig.update_geos(fitbounds="locations",visible=False)
fig.show()