lol*_*laa 9 python plotly plotly-python
是否可以在与我的绘图相同的 html 文件上添加一些文本?
例如:这是生成图表的代码:
data = pd.read_csv('file.csv')
data.columns = ['price', 'place', 'date']
fig = px.scatter(data, x = "place", y = "price", )
fig.write_html("done.html")
Run Code Online (Sandbox Code Playgroud)
该图将在 html 文件中生成 pyplot 图表,我想在图表下添加一些简单的文本(例如解释图表的结论线)。
这是我想要的输出示例: ly
ves*_*and 17
您可以使用它fig.update_layout(margin=dict())来腾出解释空间,然后在fig.add_annotation()图下方插入您想要的任何文本以获得以下结果:
import plotly.graph_objects as go
import numpy as np
x = np.arange(-4,5)
y=x**3
yticks=list(range(y.min(), y.max(), 14))
#yticks.append(y.max())9
# build figure
fig = go.Figure(data=go.Scatter(x=x, y=y))
# make space for explanation / annotation
fig.update_layout(margin=dict(l=20, r=20, t=20, b=60),paper_bgcolor="LightSteelBlue")
# add annotation
fig.add_annotation(dict(font=dict(color='yellow',size=15),
x=0,
y=-0.12,
showarrow=False,
text="A very clear explanation",
textangle=0,
xanchor='left',
xref="paper",
yref="paper"))
fig.show()
Run Code Online (Sandbox Code Playgroud)