您可以通过绘制来解决这个问题NAME2
首先是酒吧,然后是NAME1
酒吧 - 你需要设置base https://plotly.com/python/bar-charts/#customizing-individual-bar-baseNAME2 条的数量是y1_values
NAME1 条的数量(以便 NAME2 条从 NAME1 条的位置开始),然后将 NAME1 条的基数设置为 0 以确保它们从 y=0 开始。
import plotly.graph_objects as go
x_values = ['A','B','C','D','E']
y1_values = [0.527, 0.519, 0.497, 0.458, 0.445]
y2_values = [0.473, 0.481, 0.503, 0.542, 0.555]
y_errors = [0.05, 0.065, 0.158, 0.07, 0.056]
fig = go.Figure(data=[
go.Bar(name='NAME2', x=x_values, y=y2_values, base=y1_values),
go.Bar(name='NAME1', x=x_values, y=y1_values, error_y=dict(type="data", array=y_errors), base=[0]*5)
])
# Change the bar mode
fig.update_layout(barmode='stack')
fig.show()