Skip to content

Restore matplotlib backend after HoloViews matplotlib plot#1538

Open
rajeeja wants to merge 3 commits into
mainfrom
rajeeja/fix_matplotlib_backend
Open

Restore matplotlib backend after HoloViews matplotlib plot#1538
rajeeja wants to merge 3 commits into
mainfrom
rajeeja/fix_matplotlib_backend

Conversation

@rajeeja

@rajeeja rajeeja commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Calling plot(backend="matplotlib") runs hv.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 through Store.current_backend rather 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.

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread uxarray/plot/utils.py
Comment thread uxarray/plot/utils.py
Comment thread test/test_plot.py Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

simple uxarray.plot(backend="matplotlib") seems to break subsequent xarray.plot functionality

2 participants