I’m calling px.scatter
with facet_row
and facet_col
. By default, this creates subplots with repeated axis titles. This can be seen in the docs here, Facet and trellis plots in Python , where in the first example “total_bill” shows up under each subplot:
what’s the best practice for creating a facet figure with one axis title for all subplots?
related: https://community.plotly.com/t/subplots-how-to-add-master-axis-titles/
1 Like
AIMPED
March 22, 2023, 8:25pm
2
Hi @grisaitis , the only way I found is to use annotations. An example:
import plotly.express as px
df = px.data.tips()
fig = px.scatter(df, x='total_bill', y='tip', facet_col='sex', facet_row='time')
# turn off axis titels of all axes
fig.for_each_xaxis(lambda x: x.update({'title': ''}))
fig.for_each_yaxis(lambda y: y.update({'title': ''}))
# add annotations
fig.add_annotation(
showarrow=False,
xanchor='center',
xref='paper',
x=0.5,
yref='paper',
y=-0.2,
text='Master x- axis'
)
fig.add_annotation(
showarrow=False,
xanchor='center',
xref='paper',
x=-0.04,
yanchor='middle',
yref='paper',
y=0.5,
textangle=90,
text='Master y- axis'
)
creates:
thank you, @AIMPED
Would love to know if there’s a better way.
To me, this approach is simply not worth the complexity and manual effort (eg specifying x and y for each annotation, which might vary by the figure)
AIMPED
March 23, 2023, 3:12pm
4
I understand this perfectly! Unfortunately I don’t have any alternative solution.