title: Matplotlib animation.save only works when called from __main__
body: <p>I have written a function which in principle does this:</p>
  
  <pre><code>def make_animation():
      nframes = 30
      arr = np.random.rand(30, 2, 2) * 255
      data = xr.DataArray(arr, [('time', np.arange(30)), ('x', [1, 2]), ('y', [0, 1])])
      fig, ax = plt.subplots()
      quad = data.isel(time=0).plot.imshow(origin='lower',
                                       vmin=np.nanmin(data.values),
                                       vmax=np.nanmax(data.values))
  
      def update(i):
          ti = data.isel(time=i)
          quad.set_array(ti.data)
          return quad
  
      anim = animation.FuncAnimation(fig, update,
                                 frames=len(data.time), blit=False,
                                 interval=50)
      anim.save('some_path', writer='ffmpeg', fps=2)
  </code></pre>
  
  <p>It works like a charm if I call this from <code>__main__</code> for any number of <code>nframes</code>. However, if I import this function into another module it writes the output file, but doesn't "fill" it when <code>frames</code> is too high. (Too high already means 50 frames, or so). This is the last log message:</p>
  
  <pre><code> matplotlib.animation: MovieWriter.grab_frame: Grabbing frame.
  </code></pre>
  
  <p>I've tried to set the <code>save_count</code> parameter to the length of the time axis already, but it didn't change anything. Any idea how to fix this?</p>