首页 > 解决方案 > 在许多图中添加辅助轴

问题描述

我正在尝试为以下图形代码添加辅助轴。我想添加带有另一个指标的辅助轴

plt.style.use('dark_background')
fig, (ax1,ax2,ax3,ax4) = plt.subplots(nrows=4, ncols=1,figsize=(18,12))

funnel.plot(x='date_event_nk', y='Show_Complete', label='Traditional', 
ax=ax1)
ax1.set_title("TRADITIONAL FUNNEL AND YOLO CONVERSION PWA")
ax1.xaxis.set_label_coords(1.05, -0.025)

funnel_yolo.plot(x='date_event_nk', y='Show_Complete', label='Yolo', ax=ax2)
ax2.set_title("TRADITIONAL FUNNEL AND YOLO CONVERSION PWA")
ax2.xaxis.set_label_coords(1.05, -0.025)

funnel_smartlock.plot(x='date_event_nk', y='SMRequest_Complete', 
label='Smartlock Auto', ax=ax3)
ax3.set_title('SMARTLOCK AUTO CONVERSION PWA')
ax3.set_ylim((0, 0.005))
ax3.xaxis.set_label_coords(1.05, -0.025)

funnel_smartlock_s.plot(x='date_event_nk', y='SMRequest_Complete', 
label='Smartlock Select', ax=ax4)
ax4.set_title('SMARTLOCK SELECT CONVERSION PWA')
ax4.set_ylim((0, 0.1))
ax4.xaxis.set_label_coords(1.05, -0.025)

我的图表是:

在此处输入图像描述

为了在我尝试以下的所有图表中添加一个新的辅助轴(为简单起见,我只是在第一个图表中创建,我的问题在我的第一个图表中说明)

plt.style.use('dark_background')
fig, (ax1,ax2,ax3,ax4) = plt.subplots(nrows=4, ncols=1,figsize=(18,12))

funnel.plot(x='date_event_nk', y='Show_Complete', label='Traditional', 
ax=ax1)
ax1.set_title("TRADITIONAL FUNNEL AND YOLO CONVERSION PWA")
ax1.xaxis.set_label_coords(1.05, -0.025)
ax5 = ax1.twinx()
ax5.plot(kind='bar',x='date_event_nk',y='One_tap_login',ax=ax5)

funnel_yolo.plot(x='date_event_nk', y='Show_Complete', label='Yolo', ax=ax2)
ax2.set_title("TRADITIONAL FUNNEL AND YOLO CONVERSION PWA")
ax2.xaxis.set_label_coords(1.05, -0.025)

funnel_smartlock.plot(x='date_event_nk', y='SMRequest_Complete', 
label='Smartlock Auto', ax=ax3)
ax3.set_title('SMARTLOCK AUTO CONVERSION PWA')
ax3.set_ylim((0, 0.005))
ax3.xaxis.set_label_coords(1.05, -0.025)

funnel_smartlock_s.plot(x='date_event_nk', y='SMRequest_Complete', 
label='Smartlock Select', ax=ax4)
ax4.set_title('SMARTLOCK SELECT CONVERSION PWA')
ax4.set_ylim((0, 0.1))
ax4.xaxis.set_label_coords(1.05, -0.025)

但无法正常工作

标签: pythonmatplotlibplotseaborn

解决方案


推荐阅读