Python表示二次坐标(种类=';直线';)

Python表示二次坐标(种类=';直线';),python,pandas,plot,Python,Pandas,Plot,我正在尝试解决一个打印问题,之前已经报告过,熊猫打印(.plot())中有一个辅助y轴 这是我目前的代码: tfig是熊猫数据帧,如所附图片所示: 结果图如下所示。理想情况下,次y轴应在“周期1”开始,而不是在“周期2”开始 关于如何修改此代码以相应地绘制它,有什么想法吗 谢谢你的帮助 Title = 'Transport Results' xlabels = ['Period 1 (2023 - 2026)','Period 2 (2027 - 2032)','Period 3 (20

我正在尝试解决一个打印问题,之前已经报告过,熊猫打印(.plot())中有一个辅助y轴

这是我目前的代码:

tfig是熊猫数据帧,如所附图片所示:

结果图如下所示。理想情况下,次y轴应在“周期1”开始,而不是在“周期2”开始

关于如何修改此代码以相应地绘制它,有什么想法吗

谢谢你的帮助


Title = 'Transport Results'

xlabels = ['Period 1 (2023 - 2026)','Period 2 (2027 - 2032)','Period 3 (2033 - 2038)','Period 4 (2039 - 2044)','Period 5 (2045 - 2050)']

fig, ax = plt.subplots() 

ax1 = tfig[['Ship 6k', 'Ship 30k','Ship 40k','Pipe6','Pipe18','Pipe18']].plot(kind='bar',figsize=(10,6),stacked= False, color=['lightblue','deepskyblue','cyan','grey','k','darkblue'], ax=ax)

ax2 = tfig[['Trip - Ship 6k','Trip - Ship 30k','Trip - Ship 40k']].plot(stacked = True, color=['lightblue','deepskyblue','cyan'], ax=ax, secondary_y = True )

xlabels_new = [label.replace(' (', ' \n(') for label in xlabels]
ax.set_xticklabels(xlabels_new, rotation='horizontal')
ax1.set_ylim(0,12)
ax1.legend(ncol=3,loc='upper left')
ax2.legend()
ax2.set_ylim(0,1200)

plt.title(Title, fontsize=12)
plt.rcParams['font.family'] = 'serif'
plt.rcParams['font.serif'] = ['Times New Roman'] + plt.rcParams['font.serif']
plt.rcParams['font.size'] = 10

plt.savefig('test2.png', format='png')