那么如何在图表上显示每个点的值?
这是我的代码:
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()
答案 0 :(得分:2)
似乎您已经忘记在go.Scatter()中定义模式了 请添加:mode =“ lines + markers + text”
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