Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit df8f904

Browse filesBrowse files
committed
Test whether it is viable to not close figures on backend switch.
DO NOT MERGE. The desired change would need a deprecation period, but this is just to check on CI that the end state works. Do not `close("all")` figures on (allowable) backend switches, e.g. between qt5agg and qt5cairo, or qt5agg and notebook. The NonGuiException message had to change, as the backend returned by get_backend() may no longer match the actual canvas class.
1 parent f017315 commit df8f904
Copy full SHA for df8f904

File tree

Expand file treeCollapse file tree

4 files changed

+7
-9
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+7
-9
lines changed

‎lib/matplotlib/backend_bases.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backend_bases.py
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
import matplotlib as mpl
4646
from matplotlib import (
4747
_api, backend_tools as tools, cbook, colors, _docstring, text,
48-
_tight_bbox, transforms, widgets, get_backend, is_interactive, rcParams)
48+
_tight_bbox, transforms, widgets, is_interactive, rcParams)
4949
from matplotlib._pylab_helpers import Gcf
5050
from matplotlib.backend_managers import ToolManager
5151
from matplotlib.cbook import _setattr_cm
@@ -2734,8 +2734,8 @@ def show(self):
27342734
# thus warrants a warning.
27352735
return
27362736
raise NonGuiException(
2737-
f"Matplotlib is currently using {get_backend()}, which is a "
2738-
f"non-GUI backend, so cannot show the figure.")
2737+
f"{type(self.canvas).__name__} is non-interactive, and thus cannot be "
2738+
f"shown")
27392739

27402740
def destroy(self):
27412741
pass

‎lib/matplotlib/pyplot.py

Copy file name to clipboardExpand all lines: lib/matplotlib/pyplot.py
+1-4Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -391,11 +391,8 @@ def draw_if_interactive():
391391
# Need to keep a global reference to the backend for compatibility reasons.
392392
# See https://github.com/matplotlib/matplotlib/issues/6092
393393
matplotlib.backends.backend = newbackend
394-
if not cbook._str_equal(old_backend, newbackend):
395-
close("all")
396394

397-
# make sure the repl display hook is installed in case we become
398-
# interactive
395+
# Make sure the repl display hook is installed in case we become interactive.
399396
install_repl_displayhook()
400397

401398

‎lib/matplotlib/tests/test_backend_bases.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_backend_bases.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,13 @@ def test_non_gui_warning(monkeypatch):
8585
with pytest.warns(UserWarning) as rec:
8686
plt.show()
8787
assert len(rec) == 1
88-
assert ('Matplotlib is currently using pdf, which is a non-GUI backend'
88+
assert ('FigureCanvasPdf is non-interactive, and thus cannot be shown'
8989
in str(rec[0].message))
9090

9191
with pytest.warns(UserWarning) as rec:
9292
plt.gcf().show()
9393
assert len(rec) == 1
94-
assert ('Matplotlib is currently using pdf, which is a non-GUI backend'
94+
assert ('FigureCanvasPdf is non-interactive, and thus cannot be shown'
9595
in str(rec[0].message))
9696

9797

‎lib/matplotlib/tests/test_backends_interactive.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_backends_interactive.py
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ def check_alt_backend(alt_backend):
145145
fig = plt.figure()
146146
assert (type(fig.canvas).__module__ ==
147147
f"matplotlib.backends.backend_{alt_backend}")
148+
plt.close("all")
148149

149150
if importlib.util.find_spec("cairocffi"):
150151
check_alt_backend(backend[:-3] + "cairo")

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.