Reputation: 368
is there a possibility to use fixed ratio axes in combination with subplots created by plotly.express
by using facetrow
/ facetcol
This example works perfectly fine:
import plotly.express as px
df = px.data.iris()
fig = px.scatter(df, x="sepal_width", y="sepal_length", facet_col='species')
fig.update_layout(yaxis=dict(scaleanchor="x", scaleratio=1))
As soon as I add the facetrow
argument it does not adjust the axis.
Can I maybe set a default layout for the subplots using
layout = go.Layout(yaxis=dict(scaleanchor="x", scaleratio=1))
Thank you for your help,
Sören
Upvotes: 1
Views: 1455
Reputation: 839
when creating facets plotly.express
matches axes together so that you can synchronize the subplots when zooming, panning etc. This behaviour is not compatible with constraining axes aspect ratio. The code below where you disable axis matching gives the desired behaviour:
import plotly.express as px
df = px.data.iris()
fig = px.scatter(df, x="sepal_width", y="sepal_length", facet_col='species')
fig.update_yaxes(matches=None, showticklabels=True)
fig.update_xaxes(matches=None)
fig.update_layout(yaxis=dict(scaleanchor="x"))
fig.update_layout(yaxis2=dict(scaleanchor="x2"))
fig.update_layout(yaxis3=dict(scaleanchor="x2"))
fig.show()
Upvotes: 2