[英]No output from Plotly express choropleth
I am unable to get a plot of choropleth map from the given code.我无法从给定的代码中获得 plot 的 choropleth map。 I have tried it on Google colab and VS Code on my laptop but its not showing any output.....
我已经在笔记本电脑上的 Google colab 和 VS Code 上试过了,但它没有显示任何 output .....
I have also tried double clicking but that's not working...我也试过双击但那不起作用......
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()
The link to the required files are 所需文件的链接是
Thank You in advance.......先感谢您.......
Specify the feature_id from the geojson to use as reference.从 geojson 中指定 feature_id 以用作参考。
fig = px.choropleth(
y, geojson=x,
featureidkey="properties.ID_2",
locations="id",
color="Females"
)
I do not see a column for Females or ID in the user data presented.我在显示的用户数据中没有看到女性或 ID 列。 That is the reason.
这就是原因。 I created a choropleth map from the presented geosjon data with sample data.
我使用示例数据从提供的 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.