gpt4 book ai didi

python - Plotly - 在 createtd 跟踪后更新子图标题

转载 作者:行者123 更新时间:2023-12-04 11:35:49 26 4
gpt4 key购买 nike

我有一个由子图组成的 plotly 图 -

fig = make_subplots(
rows=3, cols=1)

fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1)
fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=2, col=1)
fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=3, col=1)
我要为每个子图添加一个标题,但只有在创建图形并添加跟踪之后。即不是当我创建图形时 -
fig = make_subplots(
rows=3, cols=1, subplot_titles=['a', 'b', 'c']
我可以通过 fig.update_layout 做吗?或类似的东西?

最佳答案

make_subplots用于创建(正确放置)注释。因此,这主要可以使用注释方法进行复制。一般来说,对于第一个:

fig.add_annotation(xref="x domain",yref="y domain",x=0.5, y=1.2, showarrow=False,
text="a", row=1, col=1)
缺点是您可能需要调整 xy根据您的条件/口味。
完整示例,使用粗体文本:
import plotly.graph_objects as go
from plotly.subplots import make_subplots

fig = make_subplots(rows=3, cols=1)

fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1)
fig.add_annotation(xref="x domain",yref="y domain",x=0.5, y=1.2, showarrow=False,
text="<b>Hey</b>", row=1, col=1)

fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=2, col=1)
fig.add_annotation(xref="x domain",yref="y domain",x=0.5, y=1.2, showarrow=False,
text="<b>Bee</b>", row=2, col=1)

fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=3, col=1)
fig.add_annotation(xref="x domain",yref="y domain",x=0.5, y=1.2, showarrow=False,
text="<b>See</b>", row=3, col=1)

fig.show()
enter image description here

关于python - Plotly - 在 createtd 跟踪后更新子图标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64645343/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com