为什么legend和ylabel即使使用紧凑布局也会显示盖轴刻度?

2024-06-16 10:17:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用plt.tight_布局创建了一个图表,但标签和图例覆盖了我的轴。为什么?

fig7 = plt.figure(figsize=(19/2.54,10/2.54))
ax1 = fig7.add_subplot(1,1,1)
ax1.scatter(S1_daily.loc[S1_daily['Work Type'] !='DHW', 'Date'],S1_daily.loc[S1_daily['Work Type'] !='DHW', 'eta daily (PCS)'], color='k',s=9, label='\u03B7_day (SH & DHW)')
ax1.scatter(S1_daily.loc[S1_daily['Work Type'] =='DHW', 'Date'],S1_daily.loc[S1_daily['Work Type'] =='DHW', 'eta daily (PCS)'], facecolors='none', edgecolors='k',s=11, label='\u03B7_day (Only DHW)')
ax1.set_ylabel('\u03B7_day (-)')
ax2 = ax1.twinx()
ax2.scatter(S1_daily.loc[S1_daily['Work Type'] !='DHW', 'Date'],S1_daily.loc[S1_daily['Work Type'] !='DHW', 'Qmean gas allday(kW)'], marker='^', color='r',s=9, label='Qgas_day (SH & DHW)')
ax2.scatter(S1_daily.loc[S1_daily['Work Type'] =='DHW', 'Date'],S1_daily.loc[S1_daily['Work Type'] =='DHW', 'Qmean gas allday(kW)'], marker='^', facecolors='none', edgecolors='r',s=11, label='Qgas_day (Only DHW)')
plt.gcf().subplots_adjust(right=1.08)
ax2.set_ylabel('Qgas_day (kW)', rotation=270)
fig7.legend(loc='lower center', bbox_to_anchor=(0.5, -0.007),ncol=2, fontsize=7)
plt.tight_layout()


在这里你可以找到我的实际情况: https://docdro.id/asLjp4D


Tags: datetypepltloclabelworkdailyday