3

I generated a plot in plotly using plotly.express. I used a pandas.DataFrame and one column to differentiate the two subplots putting it into facet_row Now my data has very different scales they are operating one, but plotly assigns the same range to both yaxis. I've tried to assign a 'range' attribute to the .layout.yaxis1 dictionary (using a list), but this changes the yaxis for both the upper and the lower plot. Minimal working example:

import plotly.express as px px.bar(pd.DataFrame({'x':[50,60,45,.80],'y': [800,900,1,2],"dif":['a','a','b','b']}),x='x',y='y',facet_row='dif') 

How can I change the first axis alone?

1 Answer 1

3

If you add .update_yaxes(matches=None) that will break the linkage between the Y-axis ranges.

This works because px.bar() (and any other px.*()) returns a Figure object which are are updatable via various .update_*() methods. These methods mutate and return the figure. px.bar(facet_row="whatever") by default sets the yxaxis*.matches attribute to y1 and so clearing that via .update_yaxes() will get the behaviour you want.

After that you can set the range independently however you like.

More information here: https://plot.ly/python/creating-and-updating-figures/

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.