[英]No output from Plotly express choropleth
我无法从给定的代码中获得 plot 的 choropleth map。 我已经在笔记本电脑上的 Google colab 和 VS Code 上试过了,但它没有显示任何 output .....
我也试过双击但那不起作用......
import json
import pandas as pd
import plotly.express as px
import plotly.io as pio
pio.renderers.default = 'browser'
x = json.load(open("odisha_disticts.geojson","r"))
y = pd.read_csv("data.csv")
y.drop("Unnamed: 0",axis = 'columns',inplace=True)
fig = px.choropleth(
y,
locations="id",
geojson=x,
color="Females"
)
fig.update_geos(fitbounds="locations", visible=False)
fig.show()
先感谢您.......
从 geojson 中指定 feature_id 以用作参考。
fig = px.choropleth(
y, geojson=x,
featureidkey="properties.ID_2",
locations="id",
color="Females"
)
我在显示的用户数据中没有看到女性或 ID 列。 这就是原因。 我使用示例数据从提供的 geosjon 数据创建了一个 choropleth map。
import json
import pandas as pd
import numpy as np
import plotly.express as px
import plotly.io as pio
#pio.renderers.default = 'browser'
x = json.load(open("./odisha_disticts.geojson","r"))
user_data = []
for i in range(len(x['features'])):
d = x['features'][i]['properties']
d['Females'] = np.random.randint(0,100,1)[0]
user_data.append(d)
df = pd.DataFrame(user_data)
df.head()
ID_2 NAME_2 Females
0 16084 Angul 19
1 16085 Baleshwar 45
2 16086 Baragarh 52
3 16087 Bhadrak 81
4 16088 Bolangir 49
fig = px.choropleth(
df,
locations="ID_2",
featureidkey="properties.ID_2",
geojson=x,
color="Females"
)
fig.update_geos(fitbounds="locations", visible=False)
fig.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.