✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🧬 Learn how to build RNA-Seq data apps with Python & Dash. Register for the May 20 Webinar!

Add button to change from linear scale to log scale

Hey all, based on answers to some other questions I was trying to plot a time series where I can switch from linear to log scale on the y axis. It seems the way to go is using updatemenus, so I tried this:

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='date', y='total_cases', color='country') #Time series for all countries in my table

    fig.update_layout(
        updatemenus=updatemenus
    )

This brings me this plot:

enter image description here

Which looks fine, but, when I press log scale, the plot remains the same:

enter image description here

What am I missing? I guess it’s something simple. Any help would be kindly appreciated

1 Like

@Juanouo
You have to use the method “relayout” and as args:
[{"yaxis.type": "log"}]
The reason why you have to change your definition is explained here: https://plotly.com/~empet/15608.
The first example in this tutorial is just switching from linear to log scale.

1 Like

Thanks a lot, @empet, my brain was burning and I couldn’t find any help for my problem. Worked like a charm !