添加按钮以在Plotly Dash中从线性刻度切换到对数刻度

问题描述 投票:0回答:1

此问题与this one几乎相同。问题是,我无法使其正常运行。相关代码:

df = pd.DataFrame({'country': {4048: 'Chile',
  4053: 'Chile',
  17294: 'Spain',
  17303: 'Spain',
  17307: 'Spain',
  17312: 'Spain',
  17313: 'Spain',
  17316: 'Spain'},
 'total_cases': {4048: 1610.0,
  4053: 3031.0,
  17294: 430.0,
  17303: 9191.0,
  17307: 19980.0,
  17312: 47610.0,
  17313: 56188.0,
  17316: 78797.0},
 't_100_cases': {4048: 12.0,
  4053: 17.0,
  17294: 6.0,
  17303: 15.0,
  17307: 19.0,
  17312: 24.0,
  17313: 25.0,
  17316: 28.0}})


updatemenus = [
    dict(
        type="buttons",
        direction="left",
        buttons=list([
            dict(
                args=[{'yaxis': {'type': 'linear'}}],
                label="Linear Scale",
                method="update"
            ),
            dict(
                args=[{'yaxis': {'type': 'log'}}],
                label="Log Scale",
                method="update"
            )
        ])
    ),
]  

    fig = px.line(df, x='t_100_cases', y='total_cases', color='country',
                  labels={'t_100_cases': 'Días desde los 100 contagiados',
                          'total_cases': 'Total de casos'},
                  title='Evolución de casos totales')

    fig.update_layout(
        updatemenus=updatemenus
    )

这为我带来了这个剧情:]

enter image description here

看起来不错,但是当我按对数刻度时,图保持不变:

enter image description here

我想念的是什么?我想这很简单。

这个问题与这个问题几乎相同。问题是,我无法使其正常运行。相关代码:df = pd.DataFrame({'country':{4048:'智利',4053:'智利',17294:'西班牙',17303:...

python plotly plotly-dash
1个回答
0
投票

我找到了答案。我需要在updatemenus中进行两项更改:

© www.soinside.com 2019 - 2024. All rights reserved.