Skip to content

fix(pyplot): an inline notebook animation leaves matplotlib's interactive mode alone - #921

Merged
petercorke merged 1 commit into
mainfrom
fix/inline-keeps-interactive-mode
Nov 1, 2026
Merged

petercorke merged 1 commit into
mainfrom
fix/inline-keeps-interactive-mode

Conversation

@petercorke

Copy link
Copy Markdown
Owner

Launching an animation in a notebook (the notebook-inline render mode) called plt.ioff() and never undid it. With the ipympl backend, a figure made in a later cell is only displayed at the end of the cell if Matplotlib's interactive mode is on, so a plain fig, ax = plt.subplots() after an RTB animation showed nothing until plt.show() was called. I saw this in VS Code, Google Colab and JupyterLite, with the same result in each.

The inline figure is detached from pyplot (plt.close(self.fig)) and drawn by _push_inline_frame(), so interactive mode has no effect on it. The fix is to not change it. I checked with the real ipympl backend that the animation is identical with and without the call: the same frames, no widget displayed, no figure registered with pyplot. The window and notebook-widget modes are unchanged.

Does this change numerical results or public behaviour? No numerical results change. After an inline animation, Matplotlib's interactive mode is left as the user had it, where before it was off.

Tested: three new tests in tests/test_render_mode.py check that interactive mode is unchanged after an inline launch (on and off), after an animation, and that a widget launch still turns it on. Two of them fail without the change. They check the state, not the display, which needs a real notebook frontend. The wider plotting, backend and mobile tests pass (550) and mypy 2.4.1 is clean.

Not yet checked on the fixed code: the display itself in VS Code, Colab and JupyterLite. A manual test notebook for that exists; I will not merge until it has been run on this branch.

This change was written with Claude Code (Claude Sonnet 5.5).

🤖 Generated with Claude Code

…tive mode alone

Launching an animation in a notebook switched interactive mode off and never
restored it. With the ipympl backend a figure made in a later cell is only
displayed at the end of the cell if interactive mode is on, so a plain
plt.subplots() after an animation showed nothing until plt.show() was called.
Seen in VS Code, Colab and JupyterLite.

The inline figure is detached from pyplot and drawn by _push_inline_frame(), so
interactive mode has no effect on it; just do not change it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@codacy-production

Copy link
Copy Markdown

Not up to standards ⛔

🔴 Issues 2 high

Alerts:
⚠ 2 issues (≤ 0 issues of at least minor severity)

Results:
2 new issues

Category Results
ErrorProne 2 high

View in Codacy

🟢 Metrics 7 complexity · -1 duplication

Metric Results
Complexity 7
Duplication -1

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@petercorke
petercorke merged commit e554f45 into main Nov 1, 2026
23 of 24 checks passed
@petercorke
petercorke deleted the fix/inline-keeps-interactive-mode branch November 1, 2026 21:27
@github-actions github-actions Bot mentioned this pull request Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant