今天想用python做個demo,含兩個子圖的動態gif,代碼如下:
import matplotlib.pyplot as plt
import imageio,os
import matplotlib
# plt.ion()
fig=plt.figure(0)
ax1=plt.subplot(121)
ax2=plt.subplot(122)
ax1.set_title('input')
ax2.set_title('GT')
for i in range(1000):
img1=plt.imread('F:\\pythonprogram\\test_bord/path\\enc_in_img\\{}.png'.format(i))
img2 = plt.imread('F:\\pythonprogram\\test_bord/path\\dec_out_img\\{}.png'.format(i))
ax1.imshow(img1)
ax2.imshow(img2)
# ax2.axis('off')
plt.pause(0.00001)
plt.cla()
plt.show()
首先分別將畫布分爲兩塊,分別循環讀如圖片,顯示圖片後暫停,再清除原圖像~
但是由於plt.cla()只能作用於最後一個子圖,第一塊子圖讀取過程中佔用大量內存導致內存溢出,目前沒找到解決辦法。
最後在matlab上完成這個工作。