麻烦节约matplotlib动画 [英] Trouble saving matplotlib animation

查看:449
本文介绍了麻烦节约matplotlib动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用matplotlib,使动画热图。我已经在数据的文本文件(rs_h)3列 - X,Y,Z;我使用散点图做一个简单的热图,然后用动画包来更新随时间变化的热图

 进口大熊猫作为PD
进口matplotlib.pyplot如PLT
导入numpy的是NP
进口matplotlib.animation动画数据= pd.read_table('rs_h',标题=无09月= R\\ S *)帧= np.array_split(数据,9)高清的main():
    numframes = 9
    为NumPoints = 75    X,Y,C = np.random.random((3,为NumPoints))    图= plt.figure()
    SCAT = plt.scatter(X,Y,C = C)#,S = 100)    ANI = animation.FuncAnimation(图,update_plot,帧=的xrange(numframes)
                              间隔= 5)
    #ani.save(影片.avi,codeC ='AVI')
    plt.show()高清update_plot(ⅰ):
    帧=帧[I]
    SCAT = plt.scatter(帧[0],框架[1],C =帧[2])
    返回SCAT,主要()

我有没有麻烦动画热图;但是,我遇到一个问题,当我尝试保存动画

  /Users/Arjun/anaconda/lib/python2.7/site-packages/matplotlib/animation.py:695:UserWarning:MovieWriter FFmpeg的不可用
  warnings.warn(MovieWriter%S不可用%作家)
回溯(最近通话最后一个):
  文件heat_ani.py,第29行,上述<&模块GT;
    主要()
  文件heat_ani.py,第21行,在主
    ani.save(影片.avi,codeC ='AVI')
  文件/Users/Arjun/anaconda/lib/python2.7/site-packages/matplotlib/animation.py,线路712,在保存
    与writer.saving(self._fig,文件名,DPI):
AttributeError的:'海峡'对象有没有属性'节约'

任何人都知道问题是什么,怎么去解决呢?

编辑:问题是我没有安装的ffmpeg。一个简单的冲泡安装允许code工作


解决方案

我发现了一个解决方案,在这里:
<一href=\"http://nbviewer.ipython.org/github/jrjohansson/scientific-python-lectures/blob/master/Lecture-4-Matplotlib.ipynb\" rel=\"nofollow\">http://nbviewer.ipython.org/github/jrjohansson/scientific-python-lectures/blob/master/Lecture-4-Matplotlib.ipynb

基本上你需要的ffmpeg库澳新libav工具

如此开放终端和类型根


  

    

的apt-get安装的ffmpeg


  


  

    

的apt-get安装libav工具


  

希望它可以帮助。

I'm using matplotlib to make an animated heatmap. I have data in a text file (rs_h) with 3 columns - x, y, z; i'm using scatterplot to make a simple heatmap, and then using the animation package to update the heatmap over time

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.animation as animation

data = pd.read_table('rs_h', header=None, sep=r"\s*")

frames = np.array_split(data, 9)

def main():
    numframes = 9
    numpoints = 75

    x, y, c = np.random.random((3, numpoints))

    fig = plt.figure()
    scat = plt.scatter(x, y, c=c)#, s=100)

    ani = animation.FuncAnimation(fig, update_plot, frames=xrange(numframes), 
                              interval = 5)
    #ani.save("movie.avi", codec='avi')
    plt.show()

def update_plot(i):
    frame = frames[i]
    scat = plt.scatter(frame[0], frame[1], c=frame[2])
    return scat,

main()

I'm having no trouble getting the animated heatmap; however, i run into an issue when i try to save the animation

/Users/Arjun/anaconda/lib/python2.7/site-packages/matplotlib/animation.py:695: UserWarning: MovieWriter ffmpeg unavailable
  warnings.warn("MovieWriter %s unavailable" % writer)
Traceback (most recent call last):
  File "heat_ani.py", line 29, in <module>
    main()
  File "heat_ani.py", line 21, in main
    ani.save("movie.avi", codec='avi')
  File "/Users/Arjun/anaconda/lib/python2.7/site-packages/matplotlib/animation.py", line 712, in save
    with writer.saving(self._fig, filename, dpi):
AttributeError: 'str' object has no attribute 'saving'

Anyone know what the issue is and how to get around it?

EDIT: The issue was that i didn't have ffmpeg installed. A simple brew install allowed the code to work

解决方案

I found a solution here: http://nbviewer.ipython.org/github/jrjohansson/scientific-python-lectures/blob/master/Lecture-4-Matplotlib.ipynb

Basically you need ffmpeg library o the newer libav-tools

so open terminal and type as root

apt-get install ffmpeg

or

apt-get install libav-tools

Hope it might help.

这篇关于麻烦节约matplotlib动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆