2011-02-22 57 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