feat: decouple Matplotlib render resolution (DPI) from display size#9144
Merged
Light2Dark merged 2 commits intomarimo-team:mainfrom Apr 13, 2026
Merged
feat: decouple Matplotlib render resolution (DPI) from display size#9144Light2Dark merged 2 commits intomarimo-team:mainfrom
Light2Dark merged 2 commits intomarimo-team:mainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Bundle ReportBundle size has no change ✅ |
Light2Dark
previously approved these changes
Apr 13, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Decouples Matplotlib PNG render resolution (DPI) from the notebook display size so users can increase sharpness without expanding plot layout (closes #9124).
Changes:
- Remove “retina” hardcoding and render PNGs at the figure’s actual DPI.
- Normalize PNG display metadata (width/height) to a fixed 100-DPI reference so on-screen size stays stable.
- Update/expand tests to validate DPI affects pixel resolution while display sizing metadata remains constant.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
marimo/_output/mpl.py |
Render PNG at fig.dpi and scale width/height metadata by dpi/100 to keep display size constant. |
tests/_output/formatters/test_matplotlib.py |
Replace retina-specific assertions with DPI-parameterized checks for pixel resolution and display-size metadata. |
frontend/src/components/editor/Output.tsx |
Update comment to reflect metadata’s new purpose (constant display size across DPI/PPI). |
d698a84 to
0397692
Compare
Light2Dark
approved these changes
Apr 13, 2026
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.
📝 Summary
Closes #9124
This PR decouples the internal rendering resolution (DPI) of Matplotlib figures from their display size in the marimo notebook.
The fundamental principle is that DPI should control image quality (sharpness), not the physical display size.
Previously, increasing
fig.dpito achieve a sharper image caused the plot to expand linearly, often breaking the notebook layout. This change ensures that figures maintain a consistent display size based on a 100 DPI reference (Matplotlib's default), regardless of the rendering DPI.Changes
*2DPI and//2dimensions).dpi / 100. This ensures that a figure with a givenfigsizeoccupies the same space in the notebook even if the DPI is increased for higher quality.tests/_output/formatters/test_matplotlib.pyto verify that:Verification
The following image demonstrates the fix:
fig.dpi = 20(Low resolution, correct display size)fig.dpi = 300(High resolution, same display size)savefig.format = "svg"(Consistent behavior with SVG)As shown, the display size remains stable even when the DPI is changed significantly, allowing users to control image quality without affecting the notebook layout.
📋 Pre-Review Checklist
✅ Merge Checklist