Plotly怎么再图像左上方添加多个标题

我想在图形上方添加一个如图所示的副标题,有什么办法吗? 我只能把文本添加到图像里面,不能显示在上方,大家有没有好的方法啊? 谢谢!

我的代码:

import plotly.graph_objects as go

fig = go.Figure()

fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]))


fig.update_layout(
    title = dict(
        text='Main Title',
        x=0.5,
        xanchor='center',
        yanchor='top',
        font=dict(
          color='red',
          size=24
        ),
    ),
)

fig.add_annotation(
                xref='x domain',
                yref='y domain',
                x = 0,
                y=1,
                text='这是我添加的',
                showarrow=False,
                font=dict(
                          color='blue',
                          size=18
                        ),
                )

fig.show()
Jason990420
最佳答案

I know nothing about plotly, but try to find the answer for you

Maybe it is not the best answer, but work.

from plotly.subplots import go, make_subplots

fig = make_subplots(1, 1, subplot_titles=['这是我添加的'])
fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]))
fig.update_layout(
    title = dict(
        text="Main Title",
        x=0.5,
        xanchor='center',
        yanchor='top',
        font=dict(
          color='red',
          size=24
        ),
    ),
)
fig.layout.annotations[0].update(x=0, xanchor='left', font=dict(color='blue', size=18) )
fig.show()

file

8个月前 评论
讨论数量: 1
Jason990420

I know nothing about plotly, but try to find the answer for you

Maybe it is not the best answer, but work.

from plotly.subplots import go, make_subplots

fig = make_subplots(1, 1, subplot_titles=['这是我添加的'])
fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]))
fig.update_layout(
    title = dict(
        text="Main Title",
        x=0.5,
        xanchor='center',
        yanchor='top',
        font=dict(
          color='red',
          size=24
        ),
    ),
)
fig.layout.annotations[0].update(x=0, xanchor='left', font=dict(color='blue', size=18) )
fig.show()

file

8个月前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!