【发布时间】:2021-10-30 13:52:34
【问题描述】:
您好,我对 plotly 很陌生,并尝试使用按钮选择器创建具有不同符号系统的 choropleth covid 地图。我的问题是我无法实现不同的符号系统。
提前致谢!
这是我目前所拥有的:
df= pd.read_csv (covid.csv)
data=dict(type=‘choropleth’,
locations = df[‘Name’],
locationmode = ‘country names’,
z = df[‘Total’] # I believe here is my problem if I do z=[‘total’, ‘1M_pop’] I lost data
marker_line_color = ‘black’,
marker_line_width = 0.5,
)
layout=dict(title_text = ‘Cases today by country’,
title_x = 0.5,
geo=dict(
showframe = True,
showcoastlines = True,
projection_type = ‘mercator’
)
)
map=go.Figure( data=[data], layout =layout)
#buttons test
fig[“layout”]
fig[“layout”].pop(“updatemenus”)
fig.update_geos(fitbounds=“locations”, visible=True)
button1 = dict(method = “restyle”,
args = [{‘z’: [ df[“Total”] ] }, [“colorscale”, “Greens”]],
label = “Total Cases”)
button2 = dict(method = “restyle”,
args = [{‘z’: [ df[“1M_pop”] ]},[“colorscale”, “reds”]],
label = “Cases per 1M”)
fig.update_layout(width=1000,
coloraxis_colorbar_thickness=23,
updatemenus=[dict(y=1.1,
x=0.275,
xanchor=‘right’,
yanchor=‘bottom’,
active=0,
buttons=[button1, button2])
])
plot(fig, filename=‘covid.html’)```
[plotly][1]
[1]: https://i.stack.imgur.com/BV3gh.png
【问题讨论】:
-
嗨 Omri,欢迎来到 Stack Overflow!那里的链接格式不正确。请检查您的帖子的预览并修复链接。下次请小心,并始终记住在发布之前仔细检查并查看您的问题。祝你好运:D
-
您好,欢迎您。如果您可以查看how-to-ask,然后尝试生成mcve,那就太好了。
标签: python pandas button plotly choropleth