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

Commit3ccc17b

Browse files
committed
Always attach a manager attribute (possibly None) on canvas.
This avoids the confusion in the earlier implementation of Figure.show,which checked separately for whether the attribute existed and whetherit is None, and (wrongly, I believe) handled the two cases differently.
1 parent90fba03 commit3ccc17b

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
``FigureCanvasBase`` now always has a ``manager`` attribute, which may be None
2+
``````````````````````````````````````````````````````````````````````````````
3+
4+
Previously, it did not necessarily have such an attribute. A check for
5+
``hasattr(figure.canvas, "manager")`` should now be replaced by
6+
``figure.canvas.manager is not None`` (or ``getattr(figure.canvas, "manager", None) is not None``
7+
for back-compatibility).

‎lib/matplotlib/backend_bases.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1627,6 +1627,7 @@ def __init__(self, figure):
16271627
self._is_saving=False
16281628
figure.set_canvas(self)
16291629
self.figure=figure
1630+
self.manager=None
16301631
# a dictionary from event name to a dictionary that maps cid->func
16311632
self.callbacks=cbook.CallbackRegistry()
16321633
self.widgetlock=widgets.LockDraw()
@@ -2127,7 +2128,7 @@ def get_window_title(self):
21272128
Get the title text of the window containing the figure.
21282129
Return None if there is no window (e.g., a PS backend).
21292130
"""
2130-
ifhasattr(self,"manager"):
2131+
ifself.manager:
21312132
returnself.manager.get_window_title()
21322133

21332134
defset_window_title(self,title):

‎lib/matplotlib/figure.py‎

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -430,25 +430,18 @@ def show(self, warn=True):
430430
If ``True`` and we are not running headless (i.e. on Linux with an
431431
unset DISPLAY), issue warning when called on a non-GUI backend.
432432
"""
433+
ifself.canvas.managerisNone:
434+
raiseAttributeError(
435+
"Figure.show works only for figures managed by pyplot, "
436+
"normally created by pyplot.figure()")
433437
try:
434-
manager=getattr(self.canvas,'manager')
435-
exceptAttributeErroraserr:
436-
raiseAttributeError("%s\n"
437-
"Figure.show works only "
438-
"for figures managed by pyplot, normally "
439-
"created by pyplot.figure()."%err)
440-
441-
ifmanagerisnotNone:
442-
try:
443-
manager.show()
444-
return
445-
exceptNonGuiException:
446-
pass
447-
if (backends._get_running_interactive_framework()!="headless"
448-
andwarn):
449-
cbook._warn_external('Matplotlib is currently using %s, which is '
450-
'a non-GUI backend, so cannot show the '
451-
'figure.'%get_backend())
438+
self.canvas.manager.show()
439+
exceptNonGuiException:
440+
if (backends._get_running_interactive_framework()!="headless"
441+
andwarn):
442+
cbook._warn_external(
443+
f"Matplotlib is currently using{get_backend()}, which is "
444+
f"a non-GUI backend, so cannot show the figure.")
452445

453446
def_get_axes(self):
454447
returnself._axstack.as_list()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp