[英]Python Plotly display values'labels
I have a line chart like this:我有一个这样的折线图:
so how to display the value of each point on the chart?那么如何在图表上显示每个点的值呢?
Here is my code:这是我的代码:
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()
It seems like you have forgotten to define mode inside go.Scatter() please add: mode="lines+markers+text"好像你忘记在 go.Scatter() 里面定义 mode 请添加: 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
see: https://plot.ly/python/text-and-annotations/见: https : //plot.ly/python/text-and-annotations/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.