8000 Shorten calls to apply_aspect using ternaries. · matplotlib/matplotlib@5c1f9b0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5c1f9b0

Browse files
committed
Shorten calls to apply_aspect using ternaries.
... and relying on the fact that `apply_aspect()` and `apply_aspect(None)` are equivalent.
1 parent a242de0 commit 5c1f9b0

File tree

3 files changed

+8
-30
lines changed

3 files changed

+8
-30
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2947,11 +2947,7 @@ def _update_title_position(self, renderer):
29472947
axs = self._twinned_axes.get_siblings(self) + self.child_axes
29482948
for ax in self.child_axes: # Child positions must be updated first.
29492949
locator = ax.get_axes_locator()
2950-
if locator:
2951-
pos = locator(self, renderer)
2952-
ax.apply_aspect(pos)
2953-
else:
2954-
ax.apply_aspect()
2950+
ax.apply_aspect(locator(self, renderer) if locator else None)
29552951

29562952
for title in titles:
29572953
x, _ = title.get_position()
@@ -3014,11 +3010,7 @@ def draw(self, renderer):
30143010

30153011
# loop over self and child Axes...
30163012
locator = self.get_axes_locator()
3017-
if locator:
3018-
pos = locator(self, renderer)
3019-
self.apply_aspect(pos)
3020-
else:
3021-
self.apply_aspect()
3013+
self.apply_aspect(locator(self, renderer) if locator else None)
30223014

30233015
artists = self.get_children()
30243016
artists.remove(self.patch)
@@ -4394,11 +4386,8 @@ def get_tightbbox(self, renderer=None, call_axes_locator=True,
43944386
return None
43954387

43964388
locator = self.get_axes_locator()
4397-
if locator and call_axes_locator:
4398-
pos = locator(self, renderer)
4399-
self.apply_aspect(pos)
4400-
else:
4401-
self.apply_aspect()
4389+
self.apply_aspect(
4390+
locator(self, renderer) if locator and call_axes_locator else None)
44024391

44034392
for axis in self._axis_map.values():
44044393
if self.axison and axis.get_visible():

lib/matplotlib/figure.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -206,20 +206,13 @@ def _get_draw_artists(self, renderer):
206206
key=lambda artist: artist.get_zorder())
207207
for ax in self._localaxes:
208208
locator = ax.get_axes_locator()
209-
if locator:
210-
pos = locator(ax, renderer)
211-
ax.apply_aspect(pos)
212-
else:
213-
ax.apply_aspect()
209+
ax.apply_aspect(locator(ax, renderer) if locator else None)
214210

215211
for child in ax.get_children():
216212
if hasattr(child, 'apply_aspect'):
217213
locator = child.get_axes_locator()
218-
if locator:
219-
pos = locator(child, renderer)
220-
child.apply_aspect(pos)
221-
else:
222-
child.apply_aspect()
214+
child.apply_aspect(
215+
locator(child, renderer) if locator else None)
223216
return artists
224217

225218
def autofmt_xdate(

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -420,11 +420,7 @@ def draw(self, renderer):
420420
# it adjusts the view limits and the size of the bounding box
421421
# of the Axes
422422
locator = self.get_axes_locator()
423-
if locator:
424-
pos = locator(self, renderer)
425-
self.apply_aspect(pos)
426-
else:
427-
self.apply_aspect()
423+
self.apply_aspect(locator(self, renderer) if locator else None)
428424

429425
# add the projection matrix to the renderer
430426
self.M = self.get_proj()

0 commit comments

Comments
 (0)
0