小编Jak*_*cek的帖子

Plotly.graph_objects choropleth 地图 - 如何注册点击事件?

我正在尝试可视化此数据集: https: //www.kaggle.com/sdorius/globses。我正在将plotly.graph_objects 与Python 一起使用。我的目标是制作一张全世界的分区统计图,其中显示从 1880 年到 2010 年每个十年每个国家的 SES 百分位数。此外,我希望在单击某个国家/地区时显示一个额外的条形图,显示 GDPPP 或各个国家几十年来的 SES 百分位。

我已经有了带有滑块的分区统计图来选择十年,但我被困在条形图上。代码如下所示:

import pandas as pd
import plotly.graph_objs as go

df = pd.read_csv('globses.csv', encoding='iso-8859-1')

min_year = 1880
data_all_years = []

for year in sorted(df.year.unique()):
    df_single_year = df[df['year'] == year]

    data_for_year = dict(
        type='choropleth',
        locations=df.country.unique(),
        z=df_single_year['SES'],
        locationmode='country names',
        marker=dict(
            line=dict(
                color='rgb(0,0,0)',
                width=1.5
            )
        ),
        colorbar=dict(
            title='SES'
        )
    )
    data_all_years.append(data_for_year)

steps = []
for i in range(len(data_all_years)):
    step = dict(method='restyle',
                args=['visible', [False] * len(data_all_years)],
                label='Year {}'.format(i * …
Run Code Online (Sandbox Code Playgroud)

python data-visualization plotly

6
推荐指数
0
解决办法
773
查看次数

标签 统计

data-visualization ×1

plotly ×1

python ×1