【发布时间】:2021-08-10 09:31:03
【问题描述】:
请问如何将显示文本的命令与 go.Layout 结合起来?当 go.Layout() 存在时,命令 fig.add_annotation 停止工作。 go.Layout 包含很多功能;因此,我不想改变它。
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
## sample DataFrames
df1=pd.DataFrame({'A':[1,2,3],'B':[4,5,6]})
fig = px.scatter(df1, x='A', y='B')
fig.add_annotation(text="Absolutely-positioned annotation",
x=2.5, y=4.5, showarrow=False)
layout = go.Layout(
template = "plotly_white",
title="<b>O-C diagram</b>",
font_family="Trebuchet",
title_font_family="Trebuchet",
title_font_color="Navy",
xaxis_tickformat = "5.0",
yaxis_tickformat = ".1f",
xaxis2 = XAxis(
overlaying='x',
side='top',
),
legend=dict(
yanchor="top",
y=0.99,
xanchor="left",
x=0.83,
font=dict(
family="Trebuchet",
size=20,
color="black"
),
bgcolor="LightGray",
bordercolor="Black",
borderwidth=0
),
xaxis_title=r'<i>T</i>',
yaxis_title=r'O',
title_x=0.5,
font=dict(
family="Trebuchet",
size=26,
color="Black"
),
)
fig.layout = layout
fig.show()
【问题讨论】: