您可以在情节中更改子情节标题位置吗? [英] Can you alter a subplot title location in plotly?

查看:60
本文介绍了您可以在情节中更改子情节标题位置吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将 subplot_title 添加到我的子图中时,我的标题与我的轴重叠.我可以像 matplotlib 的 ax.set_title('title', y=1.5) 一样改变子图标题的位置吗?

这是我的情节,你可以看到可舞性重叠:

这是我目前的代码:

from plotly.subplots import make_subplots类别 = ['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=类别,填写='自己',名称='集群 1',可见='传奇'),行=1,列=1)fig.add_trace(go.Scatterpolar(r=y,theta=类别,填写='自己',名称='集群 2',可见='传奇'),行=1,列=2)fig.update_layout(height=600, width=1400, title_text='所有集群的雷达图(图4)')图.show()

解决方案

我给出了部分代码答案,但您可以使用 fig['layout']['annotations'] 来完成.从官方参考

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:

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()

解决方案

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()

这篇关于您可以在情节中更改子情节标题位置吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆