Python绘图显示值的标签

2024-04-25 04:31:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我有这样的折线图: enter image description here

那么如何在图表上显示每个点的值呢?你知道吗

这是我的密码:

import plotly.graph_objects as go

x = table1['date'][:-1].values.tolist()
y = table2['revenue][:-1].values.tolist()

fig = go.Figure(go.Scatter(x=x, y=y,text=y,
            line=dict(color='firebrick', width=4)))
fig.update_layout(
    title_text='revenue in this month')

fig.show()

Tags: textimportgo密码objectsas图表fig
1条回答
网友
1楼 · 发布于 2024-04-25 04:31:00

好像你忘了在里面定义模式去吧。散开() 请添加:mode=“行+标记+文本”

fig = go.Figure(go.Scatter(x=x, y=y,text=y,
                           mode="lines+markers+text",
                           line=dict(color='firebrick', width=4)))

fig.update_traces(textposition='top center') #to change the label positions

请参见: https://plot.ly/python/text-and-annotations/

相关问题 更多 >