-
Notifications
You must be signed in to change notification settings - Fork 230
FIX: Toolbar savefig respects rcparams #615
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ianhi
wants to merge
3
commits into
matplotlib:main
Choose a base branch
from
ianhi:ian/rcparam
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
+652
−3
Conversation
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
Contributor
Collaborator
Author
|
@martinRenou if you have time to look at this that would be amazing. |
ianhi
commented
Jan 14, 2026
Fixes matplotlib#138, matplotlib#234, matplotlib#339 The Download button now respects ALL matplotlib savefig.* rcParams instead of always saving as PNG with hardcoded settings. Implementation: - Override Toolbar.save_figure() to call canvas._send_save_buffer() - Add Canvas._send_save_buffer() that calls figure.savefig() without hardcoded parameters (respects all rcParams) - Send buffer + format metadata to frontend via ipywidgets comm - Update frontend handle_save() to accept buffers from backend - Support multiple formats with correct MIME types: PNG, PDF, SVG, EPS, JPEG, TIFF, PS, TIF - Set correct file extensions based on format - Maintain backward compatibility with canvas.toDataURL() fallback Respects these rcParams: - savefig.format (png, pdf, svg, jpg, eps, etc.) - savefig.dpi (resolution) - savefig.transparent (transparent backgrounds) - savefig.facecolor (custom background colors) - All other savefig.* parameters Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Manual test notebook (tests/manual_test_rcparams_save.ipynb): - Tests all savefig.* rcParams (format, transparent, facecolor, dpi) - Tests multiple formats: PNG, PDF, SVG, JPEG - Includes verification checklist - Documents expected behavior for each test case Python unit tests (tests/test_download.py): - Test _send_save_buffer respects savefig.format (PNG, PDF, SVG) - Test download() method calls _send_save_buffer - Test Toolbar.save_figure() calls _send_save_buffer - Test respects savefig.dpi and savefig.transparent rcParams - Test warns on unsupported format (e.g., webp) - Add 'tests' to pytest testpaths in pyproject.toml Addresses issues matplotlib#138, matplotlib#234, matplotlib#339 Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
- Add public download() method to Canvas class
- Allows triggering downloads from Python code without clicking button
- Respects all savefig rcParams like the toolbar button
- Includes comprehensive docstring with examples
- Add test file demonstrating programmatic usage
Use cases:
- Batch downloading multiple figures
- Automated workflows
- Custom save logic in notebooks
Example:
fig, ax = plt.subplots()
ax.plot([1, 2, 3])
fig.canvas.download() # Triggers browser download
Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
martinRenou
approved these changes
Jan 15, 2026
Member
martinRenou
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's great! Thanks for this
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.
Make the toolbar savefig button respect the matplotlib rcparams
Closes: #138
and thereby
Closes: #234
Closes: #339
Implementation
Let the backend handle the actual buffer generation, then just add the correct mimetype to the bundle for download. Much simpler than i expected.
Tests
The most important test is the manual_test notebook i added. I ran through this and it worked for me as expected. I will try it again with the PR binder link