网络编程
位置:首页>> 网络编程>> Python编程>> python 含子图的gif生成时内存溢出的方法

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

作者:睡觉不准打呼噜  发布时间:2022-11-30 05:33:12 

标签:python,gif,内存,溢出

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

来源:https://blog.csdn.net/shuijiaobuzhundahulu/article/details/92799495

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com