🌐 AI搜索 & 代理 主页
Skip to content

Commit c8ca4fc

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 f017315 commit c8ca4fc

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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/tests/test_backend_bases.py

Lines 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

Lines 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)