我有一个使用plotly 构建堆积条形图的代码示例:
import plotly.graph_objects as go
x = ['2018-01', '2018-02', '2018-03']
fig = go.Figure(go.Bar(x=x, y=[10, 15, 3], name='Client 1'))
fig.add_trace(go.Bar(x=x, y=[12, 7, 14], name='Client 2'))
fig.update_layout(
barmode='stack',
yaxis={'title': 'amount'},
xaxis={
'type': 'category',
'title': 'month',
},
)
fig.show()
Run Code Online (Sandbox Code Playgroud)
输出以下图:
有没有办法调整绘图布局以按值对每个条形的 Y 轴进行排序?
例如,在第二条 (2018-02) 中,客户端 1 的 Y 值较高,蓝色条应位于红色条的顶部。