Repository navigation
fix(plot): a trajectory is animated whatever %matplotlib says - #860
Merged
Merged
Conversation
In a notebook with the ipympl backend a figure updates only when the kernel handles a message from the browser, which it cannot do while the cell is running, so robot.plot(q) of a trajectory showed the first and the last frame only. plot() now asks for an animation, and the render mode for an animation under ipympl is the inline one. A single pose is still an interactive widget. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
petercorke
enabled auto-merge (squash)
October 19, 2026 21:01
Not up to standards ⛔🔴 Issues
|
| Category | Results |
|---|---|
| Security | 19 high 1 critical 1 medium |
🟢 Metrics 23 complexity · -6 duplication
Metric Results Complexity 23 Duplication -6
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.
… a real IPython kernel Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #860 +/- ##
=====================================
Coverage 0.00% 0.00%
=====================================
Files 146 146
Lines 16867 16846 -21
=====================================
+ Misses 16867 16846 -21 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
robot.plot(q)of a trajectory in a notebook with%matplotlib ipymplshowed a blank figure, a long pause, and then the final frame. It now animates, whatever%matplotlibsays, with no argument needed.Cause
An
ipymplfigure updates only when the browser sends adrawmessage and the kernel handles it. While a cell is running (the animation loop inplot()) the kernel cannot, so only the first and the last frames were ever drawn. The render mode that was chosen foripymplwasnotebook-widgetfor every plot. The code of the widget branch ofstep()has not changed since the render modes were written (2026-05-29); this is a limitation of the widget mode, not a recent regression.Measured in JupyterLite 4.6.4 and ipympl 0.10 with real Chromium (Playwright), sampling the output every 0.5 s during a 100-frame trajectory: 1 distinct image while the cell ran with the old code, and the same with a synchronous
canvas.draw(), withflush_events(), and withplt.pause(), and with ipykernel 6.29.5, 7.2.0 and 7.4.0. With the existingnotebook-inlinerender mode: 13 of 13 samples different.What changes
plot()passesanimation=Trueto the backend whenqhas more than one row (only to backends with a render mode, so not Swift)._resolve_render_mode(render_mode, animation)choosesnotebook-inlinefor an animation underipympl. A single pose is stillnotebook-widget, an interactive figure; the inline backend is unchanged; an explicitrender_mode=is always used as given. The docstrings say so.PyPlot2had its own copy of_resolve_render_modeand_isnotebook; it now imports the ones inPyPlot, so the 2D backend gets the same choice.Checked in the browser with the fix and no
render_mode:%matplotlib ipymplwith a trajectory animates (13 of 13),%matplotlib inlinewith a trajectory animates (13 of 13), and%matplotlib ipymplwith one pose is still a live widget canvas.tests/test_render_mode.py(14 tests) covers the choice for each backend andanimationvalue, an explicit mode, the 2D backend sharing the function, and whatplot()passes for a trajectory, a single pose, and an explicit mode. Full suite: only the 20test_servo_half_turnfailures from the stale compiled extension in my worktree; mypy clean.tests/test_notebook_animation.py(4 tests) runs a real IPython kernel and checks, from the messages it sends, that a trajectory plotted under%matplotlib ipympland under%matplotlib inlinepushes a different frame for every step while the cell runs, that one pose under ipympl is still an interactive widget, and that an explicitrender_modeis honoured. It fails without the fix (assert 0 >= 6frames for ipympl) and takes about 6 s. It does not include a browser.ipymplis added to thedevextra for it; the test skips ifipykerneloripymplis missing.Not tried in VS Code's notebook UI, only in JupyterLab. Written with AI assistance (Claude Code).
🤖 Generated with Claude Code