我有一个分组条形图,每个条形图都有两个不同比例的y轴。我正在尝试对齐两组的x轴(y=0)。我发现在其中设置rangemode='zero'应该起作用的链接link1和link2很少,但是我的数据由负值组成,我猜这是因为将rangemode设置为0不起作用。
下面是我的代码:
import plotly.offline as plt
import plotly.graph_objs as go
traces = [go.Bar(x=[1,2,3,4], y=[-1,2,-3,4], name='y actual'),
go.Bar(x=[1], y=[0], name='y dummy', hoverinfo='none', showlegend=False),
go.Bar(x=[1],y=[0],yaxis='y2', name='y2 dummy', hoverinfo='none', showlegend=False),
go.Bar(x=[1,2,3,4], y=[22, 2, 13, 25], yaxis='y2', name='y2 actual')]
layout = go.Layout(barmode='group',
yaxis=dict(title='y actual', rangemode="tozero", anchor='x', overlaying='y2'),
yaxis2=dict(title='y2 actual', side='right', rangemode = "tozero", anchor='x'))
fig = go.Figure(data=traces, layout=layout)
plt.iplot(fig)
上面的代码生成的图:
我该如何解决这个问题?
注意:您可以在代码中看到两个虚拟跟踪。我引入了它们,这样'y actual‘和'y2 actual’这两个轨迹就不会相互重叠。有关我为什么这么做的更多信息,请查看此link
https://stackoverflow.com/questions/50880980
复制相似问题