Python - Stop Funcanimation
Does anyone know the preferred method for stopping FuncAnimation? I am using it to record data from a oscilloscope and would like to be able to pause and restart the data on demand
Solution 1:
There may be some modules but I define my own pause function. It freezes the animation by clicking somewhere on the figure. When you click again, it continues to plot the animation.
You have to define a flag before the begin of your animation. Inside your animation function (the function which will be called during you animation is plotted), you have to define a a control block like: if not pause:
and then write your codes for plotting the function below.
You may have already checked, but this page gives an example of what I mean. I guess, many people do it in this way.
Notice that, the switch for pause is done with the following function:
defonClick(event):
global pause
pause ^= True
And you have to further add this line somewhere before you call FuncAnimation
fig.canvas.mpl_connect('button_press_event', onClick)
Post a Comment for "Python - Stop Funcanimation"