python 含子图的gif生成时内存溢出的方法

2023-05-18,,

今天想用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上完成这个工作。

以上这篇python 含子图的gif生成时内存溢出的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持本站。