gpt4 book ai didi

python - Matplotlib 子图图形大小

转载 作者:行者123 更新时间:2023-12-01 04:43:18 24 4
gpt4 key购买 nike

我正在尝试缩小图形的大小,并附加标题和图例。虽然实际的图形最终符合我的喜好,但图例仍然很大,标题也从图像中消失了。包含在我的一个图的示例中。

enter image description here

下面是我绘制这些数据的代码。有人有建议让这看起来更干净吗?谢谢!

fig, ax = plt.subplots(figsize=(3,2.25))
ax.plot(df3['difference'],'r-',label="Observations")
ax.plot(df4['difference'],'b-',label='MERRA')
ax.set_xlim(0,205)
ax.set_ylim(-60,60)
plt.xlabel('Year')
plt.ylabel('Snow Depth Departures(cm)')
plt.title('Station '+str(stations[c])+' Snow Depth Correlations R='+str("%0.2f"%corr[0])+'')
ax.autoscale(False)
ax.set_xticks(np.arange(0,193,48))
ax.set_xticklabels(['1979','1983','1987','1991','1995'])
plt.legend(loc='best')

#plt.show()
plt.savefig('Z:/Dan/'+str(stations[c])+'CorrPlot.png')

最佳答案

我想你已经差不多了。尝试在 ax 上设置 xlabelylabeltitlelegend

fig, ax = plt.subplots(figsize=(3,2.25))
ax.plot(df3['difference'],'r-',label="Observations")
ax.plot(df4['difference'],'b-',label='MERRA')
ax.set_xlim(0,205)
ax.set_ylim(-60,60)
ax.set_xlabel('Year')
ax.set_ylabel('Snow Depth Departures(cm)')
ax.set_title('Station '+str(stations[c])+' Snow Depth Correlations R='+str("%0.2f"%corr[0])+'')
ax.autoscale(False)
ax.set_xticks(np.arange(0,193,48))
ax.set_xticklabels(['1979','1983','1987','1991','1995'])
ax.legend(loc='best')

关于python - Matplotlib 子图图形大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30061568/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com