在许多图中添加辅助轴

时间:2018-08-30 21:06:46

标签: python matplotlib plot seaborn

我正在尝试将辅助轴添加到以下图形代码中。我想添加带有其他指标的辅助轴

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)

我的图表是:

enter image description here

为了在所有图形中添加新的辅助轴,我正在尝试以下操作 (为简单起见,我仅在第一张图中创建,我的问题在第一张图中得到说明)

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)

但不能正常工作

0 个答案:

没有答案