如何设置两个镜像轴的单个起点?我已经用‘make_subploy’功能构建了一个图形.但我在中间有个空位.我使用的是来自Tableau data collection的‘Sample Superstore’数据集.
我的代码是:
df_oct = df.loc[(df['order_date'] > '2017-09-30') & (df['order_date'] < '2017-11-01') & (df['region'] == 'Central')]
df_sep = df.loc[(df['order_date'] > '2017-08-31') & (df['order_date'] < '2017-10-01') & (df['region'] == 'Central')]
states = pd.DataFrame(
df.loc[(df['order_date'] > '2017-08-31') & (df['order_date'] < '2017-11-01') & (df['region'] == 'Central'), 'state'].unique()
,columns=['state'])
df_oct = states.merge(df_oct.groupby(by='state', as_index=False)['sales'].sum(), how='left', on='state')
df_sep = states.merge(df_sep.groupby(by='state', as_index=False)['sales'].sum(), how='left', on='state')
df_oct['month'] = 'October'
df_sep['month'] = 'September'
tornado_df = pd.concat([df_oct, df_sep])
tornado_df.fillna(0, inplace=True)
fig = make_subplots(
rows=1
,cols=2
,vertical_spacing=0
)
fig_add = fig.add_trace(
go.Histogram(
x=tornado_df.loc[tornado_df['month'] == 'September', 'sales']
,y=tornado_df.loc[tornado_df['month'] == 'September', 'state']
,histfunc='sum'
,orientation='h'
,marker_color='#D95002'
,name='September'
,opacity=0.6)
,row=1
,col=1)
fig_add = fig.add_trace(
go.Histogram(
x=tornado_df.loc[tornado_df['month'] == 'October', 'sales']
,y=tornado_df.loc[tornado_df['month'] == 'October', 'state']
,histfunc='sum'
,orientation='h'
,marker_color='#523E89'
,name='October'
,opacity=0.6)
,row=1
,col=2)
fig_add = fig.update_xaxes(
autorange="reversed"
,row=1
,col=1)
fig_add = fig.update_yaxes(
visible=False
,row=1
,col=2)
fig_add.show()
My chart: