在Plotly中为瀑布图添加合计值列,可以通过以下步骤实现:
import plotly.graph_objects as go
import pandas as pd
data = pd.DataFrame({
'Category': ['Sales', 'Expenses', 'Profit'],
'Amount': [100, 60, 40]
})
total = data['Amount'].sum()
data = data.append({'Category': 'Total', 'Amount': total}, ignore_index=True)
fig = go.Figure(data=[go.Waterfall(
name="",
x=data['Category'],
y=data['Amount'],
measure=["relative", "relative", "total"],
textposition="outside",
)])
fig.update_layout(
title="Waterfall Chart with Total",
showlegend=False,
xaxis=dict(title="Category"),
yaxis=dict(title="Amount")
)
fig.show()
这样,就在Plotly中成功添加了合计值列的瀑布图。
推荐腾讯云相关产品:云服务器 CVM,产品介绍链接地址:https://cloud.tencent.com/product/cvm
领取专属 10元无门槛券
手把手带您无忧上云