animation.save and fig.savefig interfere with each other and raise StopIteration #17770
Comments
|
Looks like this basically comes from trying to re-draw() a figure hosting an non-repeating animation, after the animation has finished running (tbh it's not clear to me what the semantics should be). In the OP's example this comes from savefig() returning to the event loop, but this can be triggered with a single figure with import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
fig, ax = plt.subplots()
plt.plot([1,2,3],[2,4,3])
def update(frame):
return []
animation = FuncAnimation(fig, update, frames=iter(range(10)), repeat=False, blit=True, interval=100)
animation.save("hi.mp4")
fig.canvas.draw()and appears to throw at least as far back as 3.0. |
|
Hi @anntzer, thank you for your answer! In my application the animation and the figure to save are completely unrelated, they even live in different files, nevertheless I am experiencing this issue. If you have any tips on how to overcome this, please let know :). |
|
ok, I understand @anntzer 's minimal reproduction case (the animation installis a single-shot callback to run after the first On I am however at a loss for how @chisarie is triggering this issue and why saving a different figure would trigger this. If I run the code in the OP as a script (via |
If `_init_draw()` fails, assume the animation is dead, but do not fail. closes matplotlib#17770
|
I put up a draft PR, but I'm no longer sure it is right or if there is something deeper that we need to sort out. |
If `_init_draw()` fails, assume the animation is dead, but do not fail. closes matplotlib#17770
If we need to get the first frame in `_init_draw()` (because the user did not pass an initialization function) fails, warn instead of raising. closes matplotlib#17770
If we need to get the first frame in `_init_draw()` (because the user did not pass an initialization function) fails, warn instead of raising. closes matplotlib#17770


The following code snippet raises StopIteration:
The same also happens if the figure is saved before the animation.
The interesting thing is that the two parts of the script work fine when run alone, so there must be some interference between the two.
The output produced by the above code:
Matplotlib version
print(matplotlib.get_backend())): TkAggMatplotlib installed using pip inside a conda environment
The text was updated successfully, but these errors were encountered: