我有下面的情节。我想将文本放在标记上方 20px 并将其旋转 25 度。
import plotly.graph_objects as go
import pandas as pd
fig = go.Figure()
data = [[1,2.3567],
[2,5.45678],
[3,1.45678],
[4,7.45678],
[5,4.2345]]
df = pd.DataFrame(data,columns=['x','y'])
fig.add_trace(go.Scatter(
x=df['x'],
y=df['y'],
mode="lines+markers+text",
name="Lines and Text",
text=df['y'],
textfont=dict(
family="sans serif",
size=28,
color="LightSeaGreen"
)
))
fig.update_layout(showlegend=False)
fig.show()
一种方法是使用文本注释,例如。
fig.add_trace(go.Scatter(
x=df['x'],
y=df['y'],
mode="lines+markers",
name="Lines and Text"
))
for row in df.itertuples():
fig.add_annotation(
x=row.x,
y=row.y,
text=row.y,
textangle=-25,
font=dict(
family="sans serif",
size=28,
color="LightSeaGreen"
),
showarrow=False,
yshift=20
)