22

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.

Tom Ron
  • 5,906
  • 3
  • 22
  • 38

2 Answers2

30

This works with me easily:

fig.update_layout(title_text='write a title here', title_x=0.5)
Hamzah
  • 8,175
  • 3
  • 19
  • 43
7

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
        }
Daver_punk
  • 79
  • 1
  • 4