pythonplotlylabelpositionx-axis

X-axis label positioning


I made a facetted plotly histogram like so:

fig = px.histogram(df, 
                   x = "x column", 
                   color = "colour column",  
                   facet_col = 'facet column')
fig.update_xaxes(title='')
fig.update_layout(xaxis2=dict(title='lonnnnnnnnnnng x axis title'))
for anno in fig['layout']['annotations']:
    anno['text']=''
fig.update_layout({'title' : 'title'})

I got the figure below. Could someone explain how to center the xaxis2 label ('lonnnnnnnnnnng x axis title') as shown in the pic below?

Thanks!

enter image description here


Solution

  • You changed the title of xaxis to empty, and then you used the title xaxis2, you can shortcut by setting the title to 'lonnnnnnnnnnng x axis title'. It will be like this:

    fig.update_xaxes(title='lonnnnnnnnnnng x axis title')
    

    No need for the second line.