2

When adding a subplot_title to my subplots in plotly my title overlaps with my axes. Can I alter the location of the subplot title like matplotlib's ax.set_title('title', y=1.5)?

Here is my plot, as you can see danceability overlaps: enter image description here

Here is my code so far:

from plotly.subplots import make_subplots
categories = ['key', 'acousticness', 'danceability', 'energy',  'loudness',
         'speechiness', 'tempo','key']

fig = make_subplots(rows=1, cols=2, specs=[[{"type":"polar"}, {"type":"polar"}]],
                    subplot_titles=('Clustering Into 8 Playlists', 'Clustering Into 11 Playlists'))

fig.add_trace(go.Scatterpolar(
          r=x,
          theta=categories,
          fill='toself',
          name='Cluster 1',
           visible='legendonly'
    ), row=1, col=1)

fig.add_trace(go.Scatterpolar(
          r=y,
          theta=categories,
          fill='toself',
          name='Cluster 2',
           visible='legendonly'
    ), row=1, col=2)

fig.update_layout(height=600, width=1400, title_text='Radar Plot of All Clusters (Fig.4)')
fig.show()
Dom McEwen
  • 335
  • 3
  • 9

1 Answers1

4

I gave a partial code answer, but you can do it with fig['layout']['annotations']. From the official reference here.I also referred to SO's answer.

fig.update_layout(title_text='Radar Plot of All Clusters (Fig.4)') # height=600, width=1400, 
for annotation in fig['layout']['annotations']: 
        annotation['yanchor']='bottom'
        annotation['y']=1.1
        annotation['yref']='paper'
        
fig.show()

enter image description here

r-beginners
  • 31,170
  • 3
  • 14
  • 32
  • 1
    I had a similar problem with subplot titles on a 2 x 2 grid. The answer was simply fig.update_annotations(yshift=20) – A Rob4 Mar 10 '21 at 09:02