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 = [
                args=[{'yaxis': {'type': 'linear'}}],
                label="Linear Scale",
                args=[{'yaxis': {'type': 'log'}}],
                label="Log Scale",

    fig = px.line(df, x='date', y='total_cases', color='country') #Time series for all countries in my table


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

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:
The first example in this tutorial is just switching from linear to log scale.


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

@empet In order to switch between linear and log scale, we need to used updatemenus, which results in having buttons by side of the graph. I would like to keep two separate button in my dashboard, and using them I want to switch between scales. Or may be in someway move the buttons from side of the graph to above them, making part them of my dashboard layout. How do we achieve this? Thanks in advance