matplotlib / matplotlib/ipympl

figure changes size at end of loop if drawn dynamically

Open
#17 15 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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:

gyrodown

I used plt.show() at the beginning of the loop because nothing gets drawn otherwise.
Is there a way to avoid this?

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.