Center plotly title by default

Viewed 12223

I have a plotly figure which I center the title using -

fig.update_layout(
            title={
            'text' : title,
            'x':0.5,
            'xanchor': 'center'
        })

I have multiple graphs and I add this to every one of them. I wonder if I can define it in advance, e.g using config object or settings, and not do it for every chart.

2 Answers

This works with me easily:

fig.update_layout(title_text='write a title here', title_x=0.5)

you need to add the following parameters for the "y axis" to your dict as the documentation mentions it:

title = {
         'text': "Plot Title",
         'y':0.9, # new
         'x':0.5,
         'xanchor': 'center',
         'yanchor': 'top' # new
        }
Related