matplotlib / matplotlib/matplotlib

[Bug]: Animation seems to keep the last frame of an old loop

Open
#28,442 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
23.2k
Forks
8.5k
Avg merge
1d 6h
Merged PRs (30d)
66

Description

### Bug summary

I noticed this behaviour few days ago. I'm not very familiar with matplotlib so this might be user error, but it's really strange and unexpected.

### Code for reproduction

```Python
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib.collections import LineCollection
import numpy as np

fig, ax = plt.subplots()

dots = []

def init():
plt.cla()
ax.set_xlim(-1, 3)
ax.set_ylim(-1, 2)

global dots

# Initialize vertices
dot1, = ax.plot([0], [0], 'o', color='red')
dot2, = ax.plot([0], [1], 'o', color='green')
dots = [dot1, dot2]

return sum([dots], [])

def animate(frame_index):
for k, dot in enumerate(dots):
y = (frame_index % 15) / 15
dot.set_data([[k], [y]])

return sum([dots], [])

ani = animation.FuncAnimation(fig, animate, frames=15, init_func=init, blit=True)

plt.show()
```

### Actual outcome

When I move the camera using the move tool during the animation, last frame of the old animation seems to linger in some sort of buffer, until the camera is moved again.

Here, the top two dots are from the old animation loop, and the two bottom ones are from the new animation loop.

![image](https://github.com/matplotlib/matplotlib/assets/17746796/cfba4a08-e887-4a94-9d3d-718245e3f281)

### Expected outcome

I would not expect old frames to be kept anywhere, period.

### Additional information

_No response_

### Operating system

_No response_

### Matplotlib Version

3.8.4

### Matplotlib Backend

_No response_

### Python version

Python 3.10.4

### Jupyter version

_No response_

### Installation

None

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the supplied FuncAnimation reproduction and trace how blitting interacts with the camera move tool when a 15-frame loop restarts. Investigate the animation and redraw paths implicated by blit=True. Done means moving the camera no longer leaves the previous loop's final frames visible, and the reproduction behaves correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data-visualization
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.