Repository navigation
fix(notebooks): make the notebooks work on Google Colab - #911
Merged
Merged
Conversation
Colab does not ship ipympl, so "%matplotlib ipympl" failed with "module://ipympl.backend_nbagg is not a valid value for backend". Install it with the toolbox and enable Colab's custom widget manager, which ipympl figures need. Regenerated every notebook's bootstrap cell. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…on Colab A static plot with the ipympl backend created its figure with interactive mode on, so ipympl displayed it while still empty and plt.show() displayed it again. VS Code showed a blank figure and Colab showed three copies. The figure is now created with interactive mode off and its canvas displayed once, when first drawn. Colab does not update a display handle in place, so a trajectory drew a new plot per frame. It now clears the cell output for each frame, as JupyterLite does. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
_isnotebook() only accepted ZMQInteractiveShell, but Colab's shell is google.colab._shell.Shell, so Colab was treated as a desktop window. With the ipympl backend that path displayed the same figure several times and never reached the notebook rendering modes. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 12 |
| Duplication | 0 |
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.
… is displayed once The stub for display assumed every displayed object was an image, so a static ipympl plot, which now displays its canvas, raised AttributeError. Record images and widgets separately, and check that a trajectory displays no widget and a static plot displays its canvas exactly once. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This was referenced Nov 1, 2026
Merged
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.
Running the notebooks on Google Colab failed or misbehaved in four ways.
%matplotlib ipymplraisedValueError: ... module://ipympl.backend_nbagg is not a valid value for backend, because Colab does not ship ipympl. The bootstrap cell now installs it and enables Colab's custom widget manager. Every notebook's bootstrap cell is regenerated._isnotebook()only recognisedZMQInteractiveShell, so Colab was treated as a desktop window. It now recognises Colab.plt.show(): a blank figure in VS Code. It is now created quietly and displayed once, when first drawn.Does this change numerical results or public behaviour? No numerical results change. Notebook display behaviour changes as above, for Colab and for static plots with ipympl.
Tested by hand with
graphics-test.ipynb:New tests cover the Colab bootstrap branch, Colab detection and the display logic. They use mocks, so they do not exercise a real notebook frontend. The full suite passes. Not tested: the Swift cells on Colab, JupyterLite after this change, other browsers.
ioff()is also left set after an inline animation, which may stop a later plainpltfigure appearing. This predates this change and is not addressed here.This change was written with Claude Code (Claude Sonnet 5.5).
🤖 Generated with Claude Code