如何同時plot兩張圖片,不是動態圖(爲了對比)

因爲想要對比兩張圖的,所以需要同時繪出
但matplotlib在遇到plt.show()函數在阻塞模式時會掛起,
代碼並不會繼續運行,這就導致只能一張一張的顯示,不方便對比。
解決方法
利用plot.ion()函數,調節到交互模式具體流程如下:

plt.ion()#代開交互
plt.figure(2, figsize=(32, 20))#畫第一個圖
plt.plot(pre_data[:,13],pre_data[:,0],'r')
plt.show()

plt.figure(1, figsize=(32, 20))#畫第二個圖
# Plot the actual value
# plt.plot(true_data[2,:],true_data[0,:], 'b-', label = 'actual')
plt.plot(pre_data[:,13],pre_data[:,0], 'b-', label = 'actual')
# Plot the predicted values
plt.plot(true_data[2,:],true_data[1,:], 'r.', label = 'prediction')
plt.xticks(rotation = '60')
plt.legend(loc='best', prop = {'size':30})
# Graph labels
plt.xlabel('Date')
plt.ylabel(' target O3 (ug/m^3)') 
plt.title('Actual and Predicted Values')

plt.ioff() 
#一定注意plot.ioff()一定在show()前面,不然就是一閃而過
plt.show()

在這裏插入圖片描述
解決了你的問題的話,記得點贊,歡迎指正。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章