Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit02d3c1b

Browse files
committed
FIX: don't close figures is switch_backend unless really switching
closes#14426
1 parent764cc4a commit02d3c1b

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

‎lib/matplotlib/pyplot.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,6 @@ def switch_backend(newbackend):
192192
newbackend : str
193193
The name of the backend to use.
194194
"""
195-
close("all")
196-
197195
ifnewbackendisrcsetup._auto_backend_sentinel:
198196
# Don't try to fallback on the cairo-based backends as they each have
199197
# an additional dependency (pycairo) over the agg-based backend, and
@@ -213,6 +211,8 @@ def switch_backend(newbackend):
213211
switch_backend("agg")
214212
rcParamsOrig["backend"]="agg"
215213
return
214+
# have to escape the switch on access logic
215+
old_backend=dict.__getitem__(rcParams,'backend')
216216

217217
backend_name= (
218218
newbackend[9:]ifnewbackend.startswith("module://")
@@ -246,6 +246,9 @@ def switch_backend(newbackend):
246246
# Need to keep a global reference to the backend for compatibility reasons.
247247
# See https://github.com/matplotlib/matplotlib/issues/6092
248248
matplotlib.backends.backend=newbackend
249+
ifnot (isinstance(old_backend,str)and
250+
old_backend.lower()==newbackend.lower()):
251+
close("all")
249252

250253

251254
defshow(*args,**kw):

‎lib/matplotlib/tests/test_pyplot.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,14 @@ def test_pyplot_box():
5151
deftest_stackplot_smoke():
5252
# Small smoke test for stackplot (see #12405)
5353
plt.stackplot([1,2,3], [1,2,3])
54+
55+
56+
deftest_switch_backend_no_close():
57+
plt.switch_backend('agg')
58+
fig=plt.figure()
59+
fig=plt.figure()
60+
assertlen(plt.get_fignums())==2
61+
plt.switch_backend('agg')
62+
assertlen(plt.get_fignums())==2
63+
plt.switch_backend('svg')
64+
assertlen(plt.get_fignums())==0

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp