matplotlib / matplotlib/ipympl
figure changes size at end of loop if drawn dynamically
- Dominant language
- Jupyter Notebook
- Stars
- 1.7k
- Forks
- 234
- PR merge metrics
- No merged PRs in 30d
Description
As per the title, consider the following snippet:
```
import time
import ipympl
import matplotlib.pyplot as plt
fig, ax = plt.subplots(1, 1, figsize=(5, 5))
data = []
plt.show()
for idx in range(4):
data.append(idx ** 2)
ax.clear()
ax.plot(data)
fig.canvas.draw()
time.sleep(0.2)
```
and this is what I get running it:

I used `plt.show()` at the beginning of the loop because nothing gets drawn otherwise.
Is there a way to avoid this?
Contributor guide
Research direction
Start by running the provided Python snippet in a Jupyter Notebook with ipympl and observe the figure resizing during the loop. Trace the dynamic draw behavior used by the example, then verify that the figure keeps its intended size across all four updates.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- jupyter-notebook, matplotlib, python
- Domain
- data-visualization, frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100