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

Commit6cf8450

Browse files
committed
Reuse the noninteractivity warning from Figure.show in _Backend.show.
Currently, the warning message "Matplotlib is currently using ..., whichis a non-GUI backend, so cannot show the figure" and the (minor)associated logic (of catching NonGuiException) is duplicated betweenFigure.show and _Backend.show. Make the latter use the former, todeduplicate it.
1 parentb5b9a63 commit6cf8450

File tree

3 files changed

+9
-18
lines changed

3 files changed

+9
-18
lines changed

‎lib/matplotlib/backend_bases.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,8 @@ def show(cls, block=None):
185185
ifnotmanagers:
186186
return
187187
formanagerinmanagers:
188-
try:
189-
manager.show()
190-
exceptNonGuiException:
191-
warnings.warn(
192-
('matplotlib is currently using %s, which is a '+
193-
'non-GUI backend, so cannot show the figure.')
194-
%get_backend())
195-
return
188+
# Emits a warning if the backend is non-interactive.
189+
manager.canvas.figure.show()
196190
ifcls.mainloopisNone:
197191
return
198192
ifblockisNone:

‎lib/matplotlib/figure.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -439,10 +439,9 @@ def show(self, warn=True):
439439
exceptNonGuiException:
440440
pass
441441
ifwarn:
442-
warnings.warn(
443-
('matplotlib is currently using %s, which is a '+
444-
'non-GUI backend, so cannot show the figure.')
445-
%get_backend())
442+
warnings.warn('Matplotlib is currently using %s, which is a '
443+
'non-GUI backend, so cannot show the figure.'
444+
%get_backend())
446445

447446
def_get_axes(self):
448447
returnself._axstack.as_list()

‎lib/matplotlib/tests/test_backend_bases.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,11 @@ def test_non_gui_warning():
6969
withpytest.warns(UserWarning)asrec:
7070
plt.show()
7171
assertlen(rec)==1
72-
assert'matplotlib is currently using pdf, ' \
73-
'which is a non-GUI backend' \
74-
instr(rec[0].message)
72+
assert ('Matplotlib is currently using pdf, which is a non-GUI backend'
73+
instr(rec[0].message))
7574

7675
withpytest.warns(UserWarning)asrec:
7776
plt.gcf().show()
7877
assertlen(rec)==1
79-
assert'matplotlib is currently using pdf, ' \
80-
'which is a non-GUI backend' \
81-
instr(rec[0].message)
78+
assert ('Matplotlib is currently using pdf, which is a non-GUI backend'
79+
instr(rec[0].message))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp