Sören Etler
Sören Etler

Reputation: 368

Use fiexed ratio axes with plotly.express facetrow / facetcol

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))

enter image description here

Thank you for your help,

Sören

Upvotes: 1

Views: 1455

Answers (1)

Emmanuelle Gouillart
Emmanuelle Gouillart

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()

plotly express facets

Upvotes: 2

Related Questions