Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 48e5959

Browse 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 3c58e2a commit 48e5959

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2563,8 +2563,8 @@ def show(self):
25632563
# This should be overridden in GUI backends.
25642564
if cbook._get_running_interactive_framework() != "headless":
25652565
raise NonGuiException(
2566-
f"Matplotlib is currently using {get_backend()}, which is "
2567-
f"a non-GUI backend, so cannot show the figure.")
2566+
f"{type(self.canvas).__name__} is non-interactive, and thus "
2567+
f"cannot be shown")
25682568

25692569
def destroy(self):
25702570
pass

lib/matplotlib/pyplot.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ def switch_backend(newbackend):
190190
newbackend : str
191191
The name of the backend to use.
192192
"""
193-
close("all")
194193

195194
if newbackend is rcsetup._auto_backend_sentinel:
196195
# Don't try to fallback on the cairo-based backends as they each have

lib/matplotlib/tests/test_backend_bases.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ def test_non_gui_warning(monkeypatch):
6666
with pytest.warns(UserWarning) as rec:
6767
plt.show()
6868
assert len(rec) == 1
69-
assert ('Matplotlib is currently using pdf, which is a non-GUI backend'
69+
assert ('FigureCanvasPdf is non-interactive, and thus cannot be shown'
7070
in str(rec[0].message))
7171

7272
with pytest.warns(UserWarning) as rec:
7373
plt.gcf().show()
7474
assert len(rec) == 1
75-
assert ('Matplotlib is currently using pdf, which is a non-GUI backend'
75+
assert ('FigureCanvasPdf is non-interactive, and thus cannot be shown'
7676
in str(rec[0].message))
7777

7878

lib/matplotlib/tests/test_backends_interactive.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ def check_alt_backend(alt_backend):
8888
assert_equal(
8989
type(fig.canvas).__module__,
9090
"matplotlib.backends.backend_{}".format(alt_backend))
91+
plt.close("all")
9192
9293
if importlib.util.find_spec("cairocffi"):
9394
check_alt_backend(backend[:-3] + "cairo")

0 commit comments

Comments
 (0)