gpt4 book ai didi

Python Plotly 显示值的标签

转载 作者:行者123 更新时间:2023-12-01 00:44:13 31 4
gpt4 key购买 nike

我有一个像这样的折线图: 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()

最佳答案

您似乎忘记在 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

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

关于Python Plotly 显示值的标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57112559/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com