Restore matplotlib backend after HoloViews matplotlib plot#1538
Open
rajeeja wants to merge 3 commits into
Open
Restore matplotlib backend after HoloViews matplotlib plot#1538rajeeja wants to merge 3 commits into
rajeeja wants to merge 3 commits into
Conversation
plot(backend='matplotlib') calls hv.extension('matplotlib'), which switches
the active matplotlib backend and clobbers the IPython inline display hook,
silently breaking subsequent native matplotlib/xarray .plot() calls. Restore
the original matplotlib backend right after the HoloViews extension switch;
HoloViews objects still display via Store.current_backend, so this is safe.
Closes #1537
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a Jupyter/IPython plotting regression where uxarray.plot(..., backend="matplotlib") triggers hv.extension("matplotlib"), which can alter Matplotlib’s active backend and break subsequent native matplotlib/xarray plotting in the same session.
Changes:
- Restore the Matplotlib backend immediately after switching HoloViews to the matplotlib backend.
- Update
reset_mpl_backend()documentation to describe intended behavior. - Add a regression test covering backend restoration after a UXarray matplotlib-backed plot.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
uxarray/plot/utils.py |
Adds post-hv.extension("matplotlib") backend restoration and updates backend reset docstring. |
test/test_plot.py |
Adds a regression test asserting Matplotlib backend state and subsequent xarray plotting still works. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Calling
plot(backend="matplotlib")runshv.extension("matplotlib"), which switches the active matplotlib backend and clobbers the IPython inline display hook, silently breaking any subsequent native matplotlib/xarray.plot()calls. This restores the original matplotlib backend right after the HoloViews extension switch, which is safe because HoloViews objects display throughStore.current_backendrather than the active matplotlib backend. Verified in real Jupyter kernels that the reported sequence now works, with a new regression test and all plotting tests/relevant docs notebooks passing; closes #1537.