小编use*_*736的帖子

使用ArtistAnimation在matplotlib中动画制作png

我一直在尝试使用有限元方法为2D热流问题创建一系列表面图.在每个时间步,我保存了一个图而不是整个矩阵,以便更有效率.

FuncAnimation在matplotlib.animation库中遇到了麻烦,所以我决定每次都渲染一个曲面图,将曲面图保存为.png文件,然后使用它来读取该图像pyplot.imread.从那里,我想将每个图像存储到一个列表中,以便我可以使用ArtistAnimation(示例).然而,它不是制作动画,而是当我打印imgplot到屏幕时,我得到两个单独的空白图,然后我的表面图.pngs .

此外,当我尝试保存动画时,我收到以下错误消息:

AttributeError: 'module' object has no attribute 'save'.
Run Code Online (Sandbox Code Playgroud)

任何帮助从当前目录中读取一组.pngs,将它们保存在列表中,然后使用ArtistAnimation"动画"那些.pngs将非常感激.我不需要任何花哨的东西.

(注意 - 我必须使代码自动化,所以不幸的是我不能使用外部源来动画我的图像,如iMovie或ffmpeg.)

以下是我的代码:

from numpy import *
from pylab import *
import matplotlib.pyplot as plt 
import matplotlib.image as mgimg
from matplotlib import animation

## Read in graphs

p = 0
myimages = []

for k in range(1, len(params.t)):

  fname = "heatflow%03d.png" %p 
      # read in pictures
  img = mgimg.imread(fname)
  imgplot = plt.imshow(img)

  myimages.append([imgplot])

  p += 1


## …
Run Code Online (Sandbox Code Playgroud)

python animation matplotlib

5
推荐指数
1
解决办法
7519
查看次数

标签 统计

animation ×1

matplotlib ×1

python ×1