【发布时间】:2021-09-10 07:50:53
【问题描述】:
使用 plotly 在所有子图中显示注释(图例)(参考:here,here)。在以下语法中,我可以在其中一个子图中(即在图中)显示文本注释,我如何能够在所有子图中显示文本注释?
volRatio pct_chg stkClose dailyRtnsStk dailySPRtns date
0 0.001 -1.078 19.710 0.072 0.029 2009-04-02
34 0.001 -1.079 19.710 0.072 0.029 2009-04-02
69 0.001 -0.910 75.870 0.034 0.018 2009-09-28
17 0.001 -0.910 75.870 0.034 0.018 2009-09-28
70 0.002 0.000 130.900 -0.013 -0.010 2009-12-31
74 0.002 0.000 130.900 -0.013 -0.010 2009-12-31
import plotly.graph_objects as go
fig = make_subplots(
rows=2, cols=2,
subplot_titles=("Volume Ratio", "Closing Value", "EPS Over Time", "Daily Returns Stock vs S&P"))
fig.append_trace(go.Scatter(
x=fd_1.date,
y=fd_1.volRatio, name='Volume Ratio'
), row=1, col=1)
fig.append_trace(go.Scatter(
x=fd_1.date,
y=fd_1.stkClose, name='Closing Value'
), row=1, col=2)
fig.append_trace(go.Scatter(
x=fd_1.date,
y=fd_1.dailyRtnsStk, name='Daily Returns'
), row=2, col=2)
fig.append_trace(go.Scatter(
x=fd_1.date,
y=fd_1.dailySPRtns, name='S&P Returns'
), row=2, col=2)
fig.append_trace(go.Scatter(
x=fd_1.date,
y=fd_1.pct_chg, name='EPS Changes', legendgroup = '1'
), row=2, col=1)
fig.update_layout(title_text="Stacked Subplots", showlegend=False)
fig.update_annotations(dict(font_size=8))
for row in [1, 2]:
if row == 1:
#
#
fig.add_annotation(dict(x=col / 2 - 0.4, y=0.8, xref="paper", yref="paper",
text='name %d' %row, showarrow=False))
fig.show()
【问题讨论】:
标签: python matplotlib plotly