首页 > 解决方案 > 为什么即使使用紧凑的布局,legend 和 ylabel 也会显示轴刻度?

问题描述

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

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

标签: pythonplot

解决方案


推荐阅读