How to set two y axes' zero point at the same place?

Hi, in the graph, how to set the two y axes’ zero point at the same place? Like in the second graph (in which I drag them at the same place manually)


Can you provide some code examples for your graph generation so we can see what you’re currently doing?

Have you tried anything with the fig.update_yaxes() functions yet? Skimming through the docs there’s some stuff in there that possibly could work for this. I haven’t done much with a double y_axis so I’m not sure how it will react exactly. But if you can supply some samples of your code I can try some options out and see if any will work for you.

Thanks
Payton

Yeah, here is the code

Hello,

For future reference please copy paste your code into the post so people can view it easier (and so the person who is trying to help you can access your code without creating everything from scratch. To post the raw code use 3 of the in a row then put your code in then another 3 of the symbol like so (remove the spaces from my example only way I can show you is adding spaces):

` ` `
` ` `

I have found the solution to what you’re trying to do. You will need to re-code your graphs but it’s pretty easy change.

You need to make sub plots and then use the secondary_y function and then you manually set your axis range on the main and secondary yaxis to the same range

import plotly.graph_objects as go

animals=['giraffes', 'orangutans', 'monkeys']

fig = make_subplots(specs=[[{"secondary_y": True}]]) #Subplot but in the same domain so 2 graphs on top each other

fig.add_trace(go.Bar(name='NY Zoo', x=animals, y=[25, -18, 33]), secondary_y=False,) #Graph one - This is the primary yaxis
fig.add_trace(go.Bar(name='SF Zoo', x=animals, y=[1, 2, 30]),secondary_y=True,) #Graph two - This is the secondary yaxis

fig.update_yaxes(title_text="<b>primary</b> yaxis title", range=[-20,40], secondary_y=False) #Set the yaxis title and range here for primary yaxis
fig.update_yaxes(title_text="<b>secondary</b> yaxis title", range=[-20,40], secondary_y=True)#Set the yaxis title and range here for primary yaxis use the same range to make them inline with each other

fig.show()

Thanks
Payton

1 Like

Aha, really thanks for your help! So, the key point is that I should use make_subplots and the parameter secondary_y, right?

Yes that’s correct, were you able to get it to work?