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

Appearance settings

Commit 31a5d0d

Browse filesBrowse files
committed
Remove some unnecessary getattrs.
Figures always have a canvas attached (even if it's just a FigureCanvasBase), and canvases always have a "manager" attribute (which may be None). Canvases also always have a "toolbar" attribute (which also may be None). Altogether this allows avoiding a couple of getattrs.
1 parent a76e037 commit 31a5d0d
Copy full SHA for 31a5d0d

File tree

Expand file treeCollapse file tree

1 file changed

+5
-8
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+5
-8
lines changed

‎lib/matplotlib/figure.py

Copy file name to clipboardExpand all lines: lib/matplotlib/figure.py
+5-8Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2660,11 +2660,9 @@ def set_size_inches(self, w, h=None, forward=True):
26602660
raise ValueError(f'figure size must be positive finite not {size}')
26612661
self.bbox_inches.p1 = size
26622662
if forward:
2663-
canvas = getattr(self, 'canvas')
2664-
if canvas is not None:
2665-
manager = getattr(canvas, 'manager', None)
2666-
if manager is not None:
2667-
manager.resize(*(size * self.dpi).astype(int))
2663+
manager = self.canvas.manager
2664+
if manager is not None:
2665+
manager.resize(*(size * self.dpi).astype(int))
26682666
self.stale = True
26692667

26702668
def get_size_inches(self):
@@ -2759,7 +2757,7 @@ def clf(self, keep_observers=False):
27592757
ax.cla()
27602758
self.delaxes(ax) # Remove ax from self._axstack.
27612759

2762-
toolbar = getattr(self.canvas, 'toolbar', None)
2760+
toolbar = self.canvas.toolbar
27632761
if toolbar is not None:
27642762
toolbar.update()
27652763
self._axstack.clear()
@@ -2854,8 +2852,7 @@ def __getstate__(self):
28542852

28552853
# check whether the figure manager (if any) is registered with pyplot
28562854
from matplotlib import _pylab_helpers
2857-
if getattr(self.canvas, 'manager', None) \
2858-
in _pylab_helpers.Gcf.figs.values():
2855+
if self.canvas.manager in _pylab_helpers.Gcf.figs.values():
28592856
state['_restore_to_pylab'] = True
28602857
return state
28612858

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.