<h3 dir="auto">Bug report</h3>
<p dir="auto"><strong>Bug summary</strong></p>
<p dir="auto">The following code for an animated visualization stopped working after an upgrade from matplotlib 3.2.2 to 3.3.2.</p>
<p dir="auto"><strong>Code for reproduction</strong></p>
<p dir="auto">Below is a minimum code for reproducible problem.</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import numpy as np
import matplotlib.pyplot as plt
from matplotlib import animation

def create_animated_plot(xs, niter, xlim =(-1.5, 1.5), ylim = [-3, 3]):

    line_coords = np.vstack((  np.array([-1,1]), np.array([0,0]) ))
    
    boxData = [np.array([np.zeros(niter), xs])]

    fig, ax1 = plt.subplots(1,1)
    line, = ax1.plot([], [], lw=2)
    ax1.set_ylabel('position')
    ax1.set_ylim(ylim)
    ax1.set_xlim(xlim)

    lines = [ax1.plot([],[],lw=2,color=&quot;black&quot;)[0]]

    def init():
        lines[0].set_data([],[])
        return lines

    def animate(i):
        xs = [boxData[0][0, i]]
        ys = [boxData[0][1, i]]

        lines[0].set_data(line_coords[0,:]+xs[0], line_coords[1,:]+ys[0]) 
        return lines

    anim = animation.FuncAnimation(fig, animate, init_func=init,
                                frames=niter, interval=10, blit=True)
    #writer = animation.PillowWriter(fps=25) 
    #anim.save('animation.gif', writer=writer)

niter = 1001
t = np.linspace(0,10,niter)

create_animated_plot(xs =np.sin(t), niter=niter)
plt.show()"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>
<span class="pl-k">import</span> <span class="pl-s1">matplotlib</span>.<span class="pl-s1">pyplot</span> <span class="pl-k">as</span> <span class="pl-s1">plt</span>
<span class="pl-k">from</span> <span class="pl-s1">matplotlib</span> <span class="pl-k">import</span> <span class="pl-s1">animation</span>

<span class="pl-k">def</span> <span class="pl-en">create_animated_plot</span>(<span class="pl-s1">xs</span>, <span class="pl-s1">niter</span>, <span class="pl-s1">xlim</span> <span class="pl-c1">=</span>(<span class="pl-c1">-</span><span class="pl-c1">1.5</span>, <span class="pl-c1">1.5</span>), <span class="pl-s1">ylim</span> <span class="pl-c1">=</span> [<span class="pl-c1">-</span><span class="pl-c1">3</span>, <span class="pl-c1">3</span>]):

    <span class="pl-s1">line_coords</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">vstack</span>((  <span class="pl-s1">np</span>.<span class="pl-en">array</span>([<span class="pl-c1">-</span><span class="pl-c1">1</span>,<span class="pl-c1">1</span>]), <span class="pl-s1">np</span>.<span class="pl-en">array</span>([<span class="pl-c1">0</span>,<span class="pl-c1">0</span>]) ))
    
    <span class="pl-s1">boxData</span> <span class="pl-c1">=</span> [<span class="pl-s1">np</span>.<span class="pl-en">array</span>([<span class="pl-s1">np</span>.<span class="pl-en">zeros</span>(<span class="pl-s1">niter</span>), <span class="pl-s1">xs</span>])]

    <span class="pl-s1">fig</span>, <span class="pl-s1">ax1</span> <span class="pl-c1">=</span> <span class="pl-s1">plt</span>.<span class="pl-en">subplots</span>(<span class="pl-c1">1</span>,<span class="pl-c1">1</span>)
    <span class="pl-s1">line</span>, <span class="pl-c1">=</span> <span class="pl-s1">ax1</span>.<span class="pl-en">plot</span>([], [], <span class="pl-s1">lw</span><span class="pl-c1">=</span><span class="pl-c1">2</span>)
    <span class="pl-s1">ax1</span>.<span class="pl-en">set_ylabel</span>(<span class="pl-s">'position'</span>)
    <span class="pl-s1">ax1</span>.<span class="pl-en">set_ylim</span>(<span class="pl-s1">ylim</span>)
    <span class="pl-s1">ax1</span>.<span class="pl-en">set_xlim</span>(<span class="pl-s1">xlim</span>)

    <span class="pl-s1">lines</span> <span class="pl-c1">=</span> [<span class="pl-s1">ax1</span>.<span class="pl-en">plot</span>([],[],<span class="pl-s1">lw</span><span class="pl-c1">=</span><span class="pl-c1">2</span>,<span class="pl-s1">color</span><span class="pl-c1">=</span><span class="pl-s">"black"</span>)[<span class="pl-c1">0</span>]]

    <span class="pl-k">def</span> <span class="pl-en">init</span>():
        <span class="pl-s1">lines</span>[<span class="pl-c1">0</span>].<span class="pl-en">set_data</span>([],[])
        <span class="pl-k">return</span> <span class="pl-s1">lines</span>

    <span class="pl-k">def</span> <span class="pl-en">animate</span>(<span class="pl-s1">i</span>):
        <span class="pl-s1">xs</span> <span class="pl-c1">=</span> [<span class="pl-s1">boxData</span>[<span class="pl-c1">0</span>][<span class="pl-c1">0</span>, <span class="pl-s1">i</span>]]
        <span class="pl-s1">ys</span> <span class="pl-c1">=</span> [<span class="pl-s1">boxData</span>[<span class="pl-c1">0</span>][<span class="pl-c1">1</span>, <span class="pl-s1">i</span>]]

        <span class="pl-s1">lines</span>[<span class="pl-c1">0</span>].<span class="pl-en">set_data</span>(<span class="pl-s1">line_coords</span>[<span class="pl-c1">0</span>,:]<span class="pl-c1">+</span><span class="pl-s1">xs</span>[<span class="pl-c1">0</span>], <span class="pl-s1">line_coords</span>[<span class="pl-c1">1</span>,:]<span class="pl-c1">+</span><span class="pl-s1">ys</span>[<span class="pl-c1">0</span>]) 
        <span class="pl-k">return</span> <span class="pl-s1">lines</span>

    <span class="pl-s1">anim</span> <span class="pl-c1">=</span> <span class="pl-s1">animation</span>.<span class="pl-v">FuncAnimation</span>(<span class="pl-s1">fig</span>, <span class="pl-s1">animate</span>, <span class="pl-s1">init_func</span><span class="pl-c1">=</span><span class="pl-s1">init</span>,
                                <span class="pl-s1">frames</span><span class="pl-c1">=</span><span class="pl-s1">niter</span>, <span class="pl-s1">interval</span><span class="pl-c1">=</span><span class="pl-c1">10</span>, <span class="pl-s1">blit</span><span class="pl-c1">=</span><span class="pl-c1">True</span>)
    <span class="pl-c">#writer = animation.PillowWriter(fps=25) </span>
    <span class="pl-c">#anim.save('animation.gif', writer=writer)</span>

<span class="pl-s1">niter</span> <span class="pl-c1">=</span> <span class="pl-c1">1001</span>
<span class="pl-s1">t</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">linspace</span>(<span class="pl-c1">0</span>,<span class="pl-c1">10</span>,<span class="pl-s1">niter</span>)

<span class="pl-en">create_animated_plot</span>(<span class="pl-s1">xs</span> <span class="pl-c1">=</span><span class="pl-s1">np</span>.<span class="pl-en">sin</span>(<span class="pl-s1">t</span>), <span class="pl-s1">niter</span><span class="pl-c1">=</span><span class="pl-s1">niter</span>)
<span class="pl-s1">plt</span>.<span class="pl-en">show</span>()</pre></div>
<p dir="auto"><strong>Actual outcome</strong></p>
<p dir="auto">The actual outcome of the code is the following figure. I.e. an empty plot with all xlabels but there is no plot of the line.</p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/8252313/97584327-93631b00-1a00-11eb-8de3-2774af767b2c.png"><img src="https://user-images.githubusercontent.com/8252313/97584327-93631b00-1a00-11eb-8de3-2774af767b2c.png" alt="image" style="max-width: 100%;"></a></p>
<p dir="auto">Additionally, something that might help with the debugging, is that if the last two lines in the <code class="notranslate">create_animated_plot()</code> are uncommented,</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="    #writer = animation.PillowWriter(fps=25) 
    #anim.save('animation.gif', writer=writer)"><pre class="notranslate"><code class="notranslate">    #writer = animation.PillowWriter(fps=25) 
    #anim.save('animation.gif', writer=writer)
</code></pre></div>
<p dir="auto">the resulting gif works as expected (see below).</p>
<p dir="auto"><strong>Expected outcome</strong></p>
<p dir="auto">The code at the end of the post moves a line up and down in the y direction. It does that successfully with matplotlib 3.2.2, but not with 3.3.2. This is reproducible in different settings.</p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/8252313/97583537-ba6d1d00-19ff-11eb-930c-a6b1029bcecd.gif"><img src="https://user-images.githubusercontent.com/8252313/97583537-ba6d1d00-19ff-11eb-930c-a6b1029bcecd.gif" alt="animation" data-animated-image="" style="max-width: 100%;"></a></p>
<p dir="auto">This code was tested on the following setups (C1, C2, C3 are different computers) with the same results:</p>
<ul dir="auto">
<li>C1: A desktop with Asrock Z370 P4, Nvidia 1050 Ti, i5-8600K.<br>
Tested with:
<ul dir="auto">
<li>Python: 3.8.3, matplotlib: 3.2.2 OK</li>
<li>Python: 3.8.3, matplotlib: 3.3.2 (problematic)</li>
</ul>
</li>
<li>C2: An Acer Spin 5 SP513-52N laptop.<br>
Tested with:
<ul dir="auto">
<li>Python: 3.8.3, matplotlib: 3.2.2 OK</li>
<li>Python: 3.8.3, matplotlib: 3.3.2 (problematic)</li>
</ul>
</li>
<li>C3<br>
Tested with:
<ul dir="auto">
<li>Win 10, Python: 3.8.3, matplotlib: 3.3.2 (problematic)</li>
<li>Ubuntu 20.04, Python: 3.8.3, matplotlib: 3.1.2 OK</li>
<li>Ubuntu 20.04, Python: 3.8.3, updated to matplotlib: 3.3.2 (problematic)</li>
</ul>
</li>
</ul>
<p dir="auto">In all cases, when I upgraded the problem appeared, and when I downgraded the problem disappeared.</p>
<p dir="auto"><strong>Matplotlib version</strong></p>
<ul dir="auto">
<li>Operating system: Win10, Ubuntu 20.04</li>
<li>Matplotlib version: 3.3.2</li>
<li>Matplotlib backend (<code class="notranslate">print(matplotlib.get_backend())</code>): Qt5Agg</li>
<li>Python version: 3.8.3 (also tested in 3.7.6)</li>
<li>Jupyter version (if applicable):</li>
<li>Other libraries:</li>
</ul>
<p dir="auto">In machine C1, and C2 I installed through conda.</p>
<h3 dir="auto">Bug report</h3>
<p dir="auto"><strong>Bug summary</strong></p>
<p dir="auto">Animations need to be held in a reference so that they are not gc'ed.  I have argued against that behavior in <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="549621478" data-permission-text="Title is private" data-url="https://github.com/matplotlib/matplotlib/issues/16221" data-hovercard-type="pull_request" data-hovercard-url="/matplotlib/matplotlib/pull/16221/hovercard" href="https://github.com/matplotlib/matplotlib/pull/16221">#16221</a>, but as long as we keep it, we could at least add an internal flag tracking whether the animation has been started (I have not checked whether it would be best for this to go in <code class="notranslate">_start</code> or <code class="notranslate">_init_draw</code> or elsewhere), and emit a warning in <code class="notranslate">__del__</code> if the animation is gc'ed without ever being started, to help confused users (<a href="https://discourse.matplotlib.org/t/could-animation-be-triggered-only-when-an-onclick-event-in-silder/21534/2" rel="nofollow">https://discourse.matplotlib.org/t/could-animation-be-triggered-only-when-an-onclick-event-in-silder/21534/2</a>).  (Unless someone can think of a reason to instantiate an animation and <em>not</em> start it... and even then we could add a flag <code class="notranslate">i_really_meant_for_this_to_be_perhaps_gced_without_ever_running=True</code>, but let's not get ahead of ourselves.)</p>
<p dir="auto"><strong>Code for reproduction</strong></p>
<p dir="auto">N/A</p>
<p dir="auto"><strong>Matplotlib version</strong></p>

<ul dir="auto">
<li>Operating system:</li>
<li>Matplotlib version: master</li>
<li>Matplotlib backend (<code class="notranslate">print(matplotlib.get_backend())</code>):</li>
<li>Python version:</li>
<li>Jupyter version (if applicable):</li>
<li>Other libraries:</li>
</ul>