Repository navigation
fix(pyplot): an inline notebook animation leaves matplotlib's interactive mode alone - #921
Merged
Merged
Conversation
…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>
Not up to standards ⛔🔴 Issues
|
| Category | Results |
|---|---|
| ErrorProne | 2 high |
🟢 Metrics 7 complexity · -1 duplication
Metric Results Complexity 7 Duplication -1
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Launching an animation in a notebook (the
notebook-inlinerender mode) calledplt.ioff()and never undid it. With theipymplbackend, 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 plainfig, ax = plt.subplots()after an RTB animation showed nothing untilplt.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 realipymplbackend that the animation is identical with and without the call: the same frames, no widget displayed, no figure registered with pyplot. Thewindowandnotebook-widgetmodes 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.pycheck 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) andmypy2.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