python 条形图图注怎么集中_实际Python:怎么实现用多个Y轴对齐分组条形图中的X轴?...

一种可能的解决办法:

设置range元素,使这两个图成正比,然后轴将对齐。基本上,你的问题是一个轴必须显示负数,而另一个轴不显示负数。通过告诉y2为了表示负数,我们达到了我们的目标。from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot

import plotly.graph_objs as go

init_notebook_mode(connected=True)

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

layout = go.Layout(

barmode='group',

yaxis=dict(

title='y actual',

rangemode="tozero",

#anchor='x',

overlaying='y2',

side="left",

range = [-4, 10]

),

yaxis2=dict(

title='y2 actual',

side='right',

rangemode = "tozero",

#anchor='x',

range = [-12, 30]

)

)

# make fig

fig = go.Figure(data=traces, layout=layout)

iplot(fig)

1620

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值