2011-02-22 62 views
2

我有一組使用pylab隨時間變化繪製的數據。在圖的上方繪製一段顏色以在python中創建路徑

我可以將每個幀存儲爲一個.png並使用iMovie將它們放在一起,但是我想將曲線添加到圖中以說明之前時間點的位置。

我認爲這樣做的一種方法是在圖上設置plt.hold(True),然後在數據頂部繪製一個軸大小的白色塊(透明度值)alpha < 1在每個新的時間點。

有誰知道我該怎麼做? axisbg似乎不起作用。

非常感謝,

漢娜

回答

2

的另一種方式實現的衰落對地塊的序列路徑是改變使用.set_alpha()方法繪製項目的阿爾法值,如果它是可用於特定您正在使用的繪圖方法。

您可以通過將您正在使用的特定繪圖功能的輸出(即繪圖中的「手柄」)附加到列表中來完成此操作。然後,在每個新圖之前,您可以找到並減少該列表中每個現有項目的alpha值。

在以下示例中,將使用.remove()從圖中刪除其alpha值下降超過某個點的項目,然後將它們的句柄從列表中刪除。

import pylab as pl 

#Set a decay constant; create a list to store plot handles; create figure. 
DECAY = 2.0 
plot_handles = [] 
pl.figure() 

#Specific to this example: store x values for plotting sinusoid function 
x_axis=pl.linspace(0 , 2 * pl.pi , 100) 

#Specific to this example: cycle 50 times through 16 different sinusoid 
frame_counter = 0 
for phase in pl.linspace(0 , 2 * pl.pi * 50 , 16 * 50): 

    #Reduce alpha for each old item, and remove 
    for handle in plot_handles: 
     alpha = handle.get_alpha() 
     if alpha/DECAY > 0.01 : 
      handle.set_alpha(alpha/DECAY) 
     else: 
      handle.remove() 
      plot_handles.remove(handle) 

    #Add new output of calling plot function to list of handles 
    plot_handles += pl.plot(pl.sin(x_axis + phase) , 'bo') 

    #Redraw figure 
    pl.draw() 

    #Save image 
    pl.savefig('frame_' + str(frame_counter).zfill(8) + '.png') 
    frame_counter += 1 
相關問題