小编Dan*_*zel的帖子

matplotlib生成动画,每个文件都是一个新帧

首先,我要感谢任何能够提前通过我的人.我是Matplotlib的新手,通常也不用python代码.

我所拥有的是大量的数据文件(100's-10,000).这些文件中的每一个都有20个我想变成动画的图,其中每个文件代表不同的帧.在尝试让事情发挥作用时,代码变得令人难以置信.有6个子图(3,2,1-6).它们都共享相同的x轴.在任何给定的子图上,我都有1到6 y的值.他们还需要适当的标签,有些是'symlog'图,因为我想查看正面和负面的对数数据.我希望在不依赖于ffmpeg或mencoder的情况下形成动画,因为在运行代码的计算机上可能无法使用这些动画.看起来这个明显的解决方案在于FuncAnimation,但这真的让我太困惑了.我见过的大多数例子都只是为一个图添加了另一个点.我想在基本上20个图中替换数据.我将仅包括两个子图,并假设我足够聪明,将其推断为6 ...

我已经成功地获得了在单独的"安全"文件中形成.png文件的情节.

所以这里有一些真正的,非常丑陋的代码:

#!/usr/bin/python
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import matplotlib.animation as animation
import glob
import os
import re
from StringIO import StringIO
from matplotlib.ticker import MaxNLocator
from matplotlib.font_manager import FontProperties

def GetFiles(dir_name, extension):
    fileList = []
    for file in os.listdir(dir_name):
        index = file.find(extension)
        if index != -1:
            dirfile = os.path.join(dir_name, file)
            fileList.append(dirfile)
    return fileList

dirString = raw_input('Please enter a directory name: ')
extension = raw_input('Please enter the extension: ') …
Run Code Online (Sandbox Code Playgroud)

python animation matplotlib

2
推荐指数
1
解决办法
2809
查看次数

标签 统计

animation ×1

matplotlib ×1

python ×1