2012-08-23 22 views
4

我經歷了這個簡單的例子,這將有助於我與我的問題就來了:如何將動態pyplot保存爲電影文件?

""" 
Pyplot animation example. 

The method shown here is only for very simple, low-performance 
use. For more demanding applications, look at the animation 
module and the examples that use it. 
""" 

import matplotlib.pyplot as plt 
import numpy as np 

x = np.arange(6) 
y = np.arange(5) 
z = x * y[:,np.newaxis] 

for i in xrange(5): 
    if i==0: 
     p = plt.imshow(z) 
     fig = plt.gcf() 
     plt.clim() # clamp the color limits 
     plt.title("Boring slide show") 
    else: 
     z = z + 2 
     p.set_data(z) 

    print "step", i 
    plt.pause(0.5) 

這顯示pyplot界面的動畫,但我想保存該動畫在某些電影格式,是有辦法?

回答

3

一種方法是將所有步驟保存爲圖像,然後使用例如圖像將它們製作成電影。 ffmpeg

3

另一種將matplotlib動畫保存爲視頻的方法在本文中有解釋http://jakevdp.github.com/blog/2012/08/18/matplotlib-animation-tutorial/。它顯示了一個更高級別的解決方案,您可以將動畫指定爲隨時間變化的繪圖函數。你也不必處理保存每一幀。

+0

謝謝你的鏈接。我知道matplotlib.animation,但我浪費了一整天的時間試圖實現我的問題(不是這個例子),但沒有成功,我需要動畫在今天完成,所以我很絕望,我會很生氣一旦我找到一種方法來理解matplotlib.animation的用法,我發現它非常不直觀,這樣做是正確的。 – enedene

+0

我第二個這個建議。關於改善matplotlib存儲庫主分支中可用的節省電影方面的最新工作。動態編碼電影比保存圖像然後合併它們要快得多。 – tacaswell

相關問題