matplotlib绘图时show函数需在save函数后
2023-12-13 21:10:10
matplotlib绘图时,先调用show,后调用save函数保存图像,否则无法保存图像信息
figsize = 23,10
#fig, axes = plt.subplots(nrows=1, ncols=2)
fig, axs = plt.subplots(4, 3, sharex='col',sharey='row',figsize=figsize)
# 在每个子图中绘制一个图形
pic_number = 0
for i in range(4): ##绘制12个子图
for j in range(3):
fontsize = 10
if i == 0 and j == 0: ## 利用第一行 第一个子图设置 所有子图的title
axs[i,j].text(1.65, 1.3, 'The centroid of the west wall zonal drifts over time(2013.01-2017.10)',
fontsize = 24
)
if i == 3 : ## 最后一行子图,添加X坐标名称
axs[i][j].set_xlabel("Local Time", fontsize=fontsize)
else:
pass
#axs[i][j].scatter(MONTH_TIME[pic_number], MONTH_VELOCITY[pic_number])
#axs[i][j].plot(MONTH_TIME[pic_number], MONTH_VELOCITY[pic_number])
# 显示图例
#axs[i][j].legend()
if pic_number == 0:## 计算1月 EPB平均面积变化
#axs[i][j].set_xlabel("Local Time(January)", fontsize=fontsize)
axs[i,j].text(0.7, 0.9, 'January',
style ='italic',
fontsize = 11,
bbox ={'facecolor':'green',
'alpha':0.6, 'pad':10})
elif pic_number == 1:
#axs[i][j].set_xlabel("Local Time(February)", fontsize=fontsize)
axs[i,j].text(0.7, 0.9, 'February',
style ='italic',
fontsize = 11,
bbox ={'facecolor':'green',
'alpha':0.6, 'pad':10})
elif pic_number == 2:
#axs[i][j].set_xlabel("Local Time(March)", fontsize=fontsize)
axs[i,j].text(0.7, 0.9, 'March',
style ='italic',
fontsize = 11,
bbox ={'facecolor':'green',
'alpha':0.6, 'pad':10})
elif pic_number == 3:
#axs[i][j].set_xlabel("Local Time(April)", fontsize=fontsize)
axs[i,j].text(0.7, 0.9, 'April',
style ='italic',
fontsize = 11,
bbox ={'facecolor':'green',
'alpha':0.6, 'pad':10})
elif pic_number == 4:
#axs[i][j].set_xlabel("Local Time(May)", fontsize=fontsize)
axs[i,j].text(0.7, 0.9, 'May',
style ='italic',
fontsize = 11,
bbox ={'facecolor':'green',
'alpha':0.6, 'pad':10})
elif pic_number == 5:
#axs[i][j].set_xlabel("Local Time(June)", fontsize=fontsize)
axs[i,j].text(0.7, 0.9, 'June',
style ='italic',
fontsize = 11,
bbox ={'facecolor':'green',
'alpha':0.6, 'pad':10})
elif pic_number == 6:
#axs[i][j].set_xlabel("Local Time(July)", fontsize=fontsize)
axs[i,j].text(0.7, 0.9, 'July',
style ='italic',
fontsize = 11,
bbox ={'facecolor':'green',
'alpha':0.6, 'pad':10})
elif pic_number == 7:
#axs[i][j].set_xlabel("Local Time(August)", fontsize=fontsize)
axs[i,j].text(0.7, 0.9, 'August',
style ='italic',
fontsize = 11,
bbox ={'facecolor':'green',
'alpha':0.6, 'pad':10})
elif pic_number == 8:
#axs[i][j].set_xlabel("Local Time(September)", fontsize=fontsize)
axs[i,j].text(0.7, 0.9, 'September',
style ='italic',
fontsize = 11,
bbox ={'facecolor':'green',
'alpha':0.6, 'pad':10})
elif pic_number == 9:
#axs[i][j].set_xlabel("Local Time(October)", fontsize=fontsize)
axs[i,j].text(0.8, 0.8, 'October',
style ='italic',
fontsize = 11,
bbox ={'facecolor':'green',
'alpha':0.6, 'pad':9})
elif pic_number == 10:
#axs[i][j].set_xlabel("Local Time(November)", fontsize=fontsize)
axs[i,j].text(0.7, 0.9, 'November',
style ='italic',
fontsize = 11,
bbox ={'facecolor':'green',
'alpha':0.6, 'pad':10})
elif pic_number == 11:
#axs[i][j].set_xlabel("Local Time(December)", fontsize=fontsize)
axs[i,j].text(0.7, 0.9, 'December',
style ='italic',
fontsize = 11,
bbox ={'facecolor':'green',
'alpha':0.6, 'pad':10})
else:
pass
axs[i][j].set_ylabel("Velocity(m/s)", fontsize=fontsize)
#axs[i][j].set_xticks(time_tick, time_xticks, rotation=0, fontsize=fontsize-2)
#axs[i][j].set_xticks(time_tick)
#axs[i][j].set_xticklabels(time_xticks, rotation='vertical')
pic_number = pic_number+1
plt.show()
plt.savefig('high_low_every_v.png')
但是high_low_every_v.png图像是一片空白,说明没有保存相关图像信息。
将
plt.savefig(‘high_low_every_v.png’)
调换位置
plt.savefig(‘high_low_every_v.png’)
plt.show()
文章来源:https://blog.csdn.net/zhuiyuanzhongjia/article/details/134872739
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!