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
在一系列绘图上实现淡入淡出轨迹的另一种方法是使用
.set_alpha()
方法更改绘图项的alpha值(如果您正在使用的特定绘图方法可用)。你知道吗您可以通过将正在使用的特定绘图函数的输出(即绘图的“句柄”)附加到列表中来实现这一点。然后,在每个新的绘图之前,您可以找到并减少该列表中每个现有项的alpha值。你知道吗
在下面的示例中,使用
.remove()
从绘图中删除alpha值下降超过某个点的项,然后从列表中删除它们的句柄。你知道吗相关问题 更多 >
编程相关推荐