<div dir="auto">Vincent,<div dir="auto"><br></div><div dir="auto">I am away from my computer for the week, so my help will be limited. In my book, Interactive Applications using Matplotlib, I devote chapter 3 to the animation module. While I don't outline how one can do what you are asking for, I do detail how animations are triggered and controlled under-the-hood. Perhaps it can provide some inspirations?</div><div dir="auto"><br></div><div dir="auto">Ben Root</div><div dir="auto"><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Dec 24, 2016 3:12 AM, "Vincent FRATICELLI" <<a href="mailto:v.fraticelli@wanadoo.fr">v.fraticelli@wanadoo.fr</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p>Hi (and sorry for my poor english),</p>
<p> </p>
<p>I am a French Physics teacher, beginning with Python.</p>
<p> </p>
<p>I would like to plot animations of magnetic field lines. In the future, my aim would be to control each animation with the mouse button. The plot would began at the first click and stop at the next one.</p>
<p>For now, I simply try to plot two successives animations of field lines using funcAnimation. My problem is that the first animation is cleared when the second is plotted. How could I keep all in the figure ?</p>
<p>If anyone could help ?</p>
<p>Best regards, Vincent.</p>
<p> </p>
<p>Codes :</p>
<p>Unable to find the solution, I have removed all the loops in the script and simply made a crude copy of the first part of the script to repeat the animation. But even this don't work !</p>
<p>******************************<wbr>******************************<wbr>****************</p>
<p>import numpy as np</p>
<p>from matplotlib import pyplot as plt</p>
<p>from matplotlib import animation</p>
<p>from scipy.integrate import odeint</p>
<p> </p>
<p>"""Ce script anime progressivement une ligne de champ à partir d'un point indiqué"""</p>
<p> </p>
<p>fig = plt.figure()</p>
<p>ax = plt.axes(xlim=(-1,1), ylim=(-1, 1))</p>
<p> </p>
<p>L=np.linspace(0,1,100)</p>
<p>plt.plot(L,L)</p>
<p> </p>
<p>y0=(0.2,0.1)</p>
<p>line, = ax.plot([], [], lw=2)</p>
<p> </p>
<p>def animate(i):</p>
<p>    def F(y,t):        </p>
<p>        dy=[0,0]</p>
<p>        dy[0]=y[1]</p>
<p>        dy[1]=-y[0]</p>
<p>        return dy    </p>
<p> </p>
<p>    t_min=0;t_max=10;dt=0.1</p>
<p>    t = np.arange(t_min,i*t_max/20,dt)     </p>
<p>    y=odeint(F,y0,t)</p>
<p>    line.set_data(y[:,0],y[:,1])</p>
<p>    return line,</p>
<p> </p>
<p>anim = animation.FuncAnimation(fig, animate,frames=10,repeat=0)</p>
<p> </p>
<p># Bloc suivant identique au premier avec y0 différent</p>
<p># Son exécution efface la première ligne</p>
<p> </p>
<p>"""y0=(0.8,0.1)</p>
<p>line2, = ax.plot([], [], lw=2)</p>
<p>def animate2(i):</p>
<p>    def F(y,t):        </p>
<p>        dy=[0,0]</p>
<p>        dy[0]=y[1]</p>
<p>        dy[1]=-y[0]</p>
<p>        return dy    </p>
<p> </p>
<p>    t_min=0;t_max=10;dt=0.1</p>
<p>    t = np.arange(t_min,i*t_max/20,dt)     </p>
<p>    y=odeint(F,y0,t)</p>
<p>    line2.set_data(y[:,0],y[:,1])</p>
<p>    return line2,</p>
<p> </p>
<p>anim2 = (animation.FuncAnimation(fig, animate2,frames=10,repeat=0))</p>
<p>"""</p>
<p>plt.show()</p><br>______________________________<wbr>_________________<br>
Matplotlib-users mailing list<br>
<a href="mailto:Matplotlib-users@python.org">Matplotlib-users@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/matplotlib-users" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/matplotlib-<wbr>users</a><br>
<br></blockquote></div></div>