我试图创建一个堆积条形图,其中的线条连接条形角,就像提供的图像(条形图之间的黑色虚线)一样。我在Spyder中以离线方式执行此操作。 我还想显示那些(虚线)的百分比变化。
我到目前为止的代码:
import plotly
import plotly.offline as offline
import plotly.plotly as py
import plotly.graph_objs as go
trace1 = go.Bar(
x=['(M)', '(DM)', '(RM)'],
y=[8.12, 7.3, 8.14],
name='travel'
)
trace2 = go.Bar(
x=['(M)', '(DM)', '(RM)'],
y=[24.2, 23.2, 23],
name='service'
)
trace3 = go.Bar(
x=['(M)', '(DM)', '(RM)'],
y = [6.7, 5.7, 5.6],
name='utility'
)
trace4 = go.Scatter(
x=['(M)', '(DM)', '(RM)'],
y=[39.02, 36.2, 36.74],
)
data=[trace1, trace2, trace3, trace4]
layout= go.Layout(
barmode= 'stack',
title='Realization: 0, 0',
xaxis=dict(title='Model'),
yaxis=dict(title='Time (minutes)')
)
fig= go.Figure(data=data, layout=layout)
offline.plot(fig, image='png', filename='stacked-bar')