Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0a26da5

Browse files
committed
Deprecate position parameter to Axes.apply_aspect()
1 parent 0ab5567 commit 0a26da5

File tree

9 files changed

+52
-24
lines changed

9 files changed

+52
-24
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The parameter *position* in ``Axes.apply_aspect()``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
... is deprecated. It is considered internal API and now public use case is known.

lib/matplotlib/_tight_bbox.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,20 @@ def adjust_bbox(fig, bbox_inches, fixed_dpi=None):
3030
current_pos = ax.get_position(original=False).frozen()
3131
ax.set_axes_locator(lambda a, r, _pos=current_pos: _pos)
3232
# override the method that enforces the aspect ratio on the Axes
33-
if 'apply_aspect' in ax.__dict__:
34-
old_aspect.append(ax.apply_aspect)
33+
if '_apply_aspect' in ax.__dict__:
34+
old_aspect.append(ax._apply_aspect)
3535
else:
3636
old_aspect.append(sentinel)
37-
ax.apply_aspect = lambda pos=None: None
37+
ax._apply_aspect = lambda pos=None: None
3838

3939
def restore_bbox():
4040
for ax, loc, aspect in zip(fig.axes, locator_list, old_aspect):
4141
ax.set_axes_locator(loc)
4242
if aspect is sentinel:
4343
# delete our no-op function which un-hides the original method
44-
del ax.apply_aspect
44+
del ax._apply_aspect
4545
else:
46-
ax.apply_aspect = aspect
46+
ax._apply_aspect = aspect
4747

4848
fig.bbox = origBbox
4949
fig.bbox_inches = origBboxInches

lib/matplotlib/axes/_axes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ def inset_axes(self, bounds, *, transform=None, zorder=5, **kwargs):
410410
inset_ax = projection_class(self.figure, bounds, zorder=zorder, **pkw)
411411

412412
# this locator lets the axes move if in data coordinates.
413-
# it gets called in `ax.apply_aspect() (of all places)
413+
# it gets called in `ax._apply_aspect() (of all places)
414414
inset_ax.set_axes_locator(inset_locator)
415415

416416
self.add_child_axes(inset_ax)

lib/matplotlib/axes/_base.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,7 +1736,7 @@ def set_adjustable(self, adjustable, share=False):
17361736
and any(getattr(ax.get_data_ratio, "__func__", None)
17371737
!= _AxesBase.get_data_ratio
17381738
for ax in axs)):
1739-
# Limits adjustment by apply_aspect assumes that the axes' aspect
1739+
# Limits adjustment by _apply_aspect assumes that the axes' aspect
17401740
# ratio can be computed from the data limits and scales.
17411741
raise ValueError("Cannot set Axes adjustable to 'datalim' for "
17421742
"Axes which override 'get_data_ratio'")
@@ -1870,6 +1870,7 @@ def get_data_ratio(self):
18701870
ysize = max(abs(tymax - tymin), 1e-30)
18711871
return ysize / xsize
18721872

1873+
@_api.delete_parameter("3.6", "position")
18731874
def apply_aspect(self, position=None):
18741875
"""
18751876
Adjust the Axes for a specified data aspect ratio.
@@ -1881,10 +1882,17 @@ def apply_aspect(self, position=None):
18811882
Parameters
18821883
----------
18831884
position : None or .Bbox
1885+
18841886
If not ``None``, this defines the position of the
18851887
Axes within the figure as a Bbox. See `~.Axes.get_position`
18861888
for further details.
18871889
1890+
.. admonition:: Deprecated
1891+
1892+
Changing the *position* through ``apply_aspect`` is
1893+
considered internal API. This parameter will be removed
1894+
in the future.
1895+
18881896
Notes
18891897
-----
18901898
This is called automatically when each Axes is drawn. You may need
@@ -1900,6 +1908,23 @@ def apply_aspect(self, position=None):
19001908
matplotlib.axes.Axes.set_anchor
19011909
Set the position in case of extra space.
19021910
"""
1911+
# Note: This method is a thin wrapper that only exists for the purpose
1912+
# of not exposing the position parameter as public API.
1913+
self._apply_aspect(position)
1914+
1915+
def _apply_aspect(self, position=None):
1916+
"""
1917+
Adjust the Axes for a specified data aspect ratio.
1918+
1919+
See the docstring of the public `apply_aspect` method.
1920+
1921+
Parameters
1922+
----------
1923+
position : None or .Bbox
1924+
If not ``None``, this defines the position of the
1925+
Axes within the figure as a Bbox. See `~.Axes.get_position`
1926+
for further details.
1927+
"""
19031928
if position is None:
19041929
position = self.get_position(original=True)
19051930

@@ -2998,7 +3023,7 @@ def _update_title_position(self, renderer):
29983023

29993024
for ax in self.child_axes: # Child positions must be updated first.
30003025
locator = ax.get_axes_locator()
3001-
ax.apply_aspect(locator(self, renderer) if locator else None)
3026+
ax._apply_aspect(locator(self, renderer) if locator else None)
30023027

30033028
top = -np.inf
30043029
for ax in axs:
@@ -3061,7 +3086,7 @@ def draw(self, renderer):
30613086

30623087
# loop over self and child Axes...
30633088
locator = self.get_axes_locator()
3064-
self.apply_aspect(locator(self, renderer) if locator else None)
3089+
self._apply_aspect(locator(self, renderer) if locator else None)
30653090

30663091
artists = self.get_children()
30673092
artists.remove(self.patch)
@@ -4444,7 +4469,7 @@ def get_tightbbox(self, renderer=None, call_axes_locator=True,
44444469
return None
44454470

44464471
locator = self.get_axes_locator()
4447-
self.apply_aspect(
4472+
self._apply_aspect(
44484473
locator(self, renderer) if locator and call_axes_locator else None)
44494474

44504475
for axis in self._axis_map.values():

lib/matplotlib/axes/_secondary_axes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,13 @@ def set_location(self, location, transform=None):
136136
# this locator lets the axes move in the parent axes coordinates.
137137
# so it never needs to know where the parent is explicitly in
138138
# figure coordinates.
139-
# it gets called in ax.apply_aspect() (of all places)
139+
# it gets called in ax._apply_aspect() (of all places)
140140
self.set_axes_locator(_TransformedBoundsLocator(bounds, transform))
141141

142-
def apply_aspect(self, position=None):
142+
def _apply_aspect(self, position=None):
143143
# docstring inherited.
144144
self._set_lims()
145-
super().apply_aspect(position)
145+
super()._apply_aspect(position)
146146

147147
@_docstring.copy(Axis.set_ticks)
148148
def set_ticks(self, ticks, labels=None, *, minor=False, **kwargs):

lib/matplotlib/figure.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def __init__(self, **kwargs):
154154
self.set(**kwargs)
155155

156156
def _get_draw_artists(self, renderer):
157-
"""Also runs apply_aspect"""
157+
"""Also runs _apply_aspect"""
158158
artists = self.get_children()
159159

160160
artists.remove(self.patch)
@@ -163,12 +163,12 @@ def _get_draw_artists(self, renderer):
163163
key=lambda artist: artist.get_zorder())
164164
for ax in self._localaxes:
165165
locator = ax.get_axes_locator()
166-
ax.apply_aspect(locator(ax, renderer) if locator else None)
166+
ax._apply_aspect(locator(ax, renderer) if locator else None)
167167

168168
for child in ax.get_children():
169-
if hasattr(child, 'apply_aspect'):
169+
if hasattr(child, '_apply_aspect'):
170170
locator = child.get_axes_locator()
171-
child.apply_aspect(
171+
child._apply_aspect(
172172
locator(child, renderer) if locator else None)
173173
return artists
174174

lib/matplotlib/tests/test_axes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5700,7 +5700,7 @@ def test_shared_with_aspect_2():
57005700
axs[0].set_aspect(2, share=True)
57015701
axs[0].plot([1, 2], [3, 4])
57025702
axs[1].plot([3, 4], [1, 2])
5703-
plt.draw() # Trigger apply_aspect().
5703+
plt.draw() # Trigger _apply_aspect().
57045704
assert axs[0].get_xlim() == axs[1].get_xlim()
57055705
assert axs[0].get_ylim() == axs[1].get_ylim()
57065706

@@ -5713,7 +5713,7 @@ def test_shared_with_aspect_3():
57135713
axs[1].set_aspect(0.5, adjustable=adjustable)
57145714
axs[0].plot([1, 2], [3, 4])
57155715
axs[1].plot([3, 4], [1, 2])
5716-
plt.draw() # Trigger apply_aspect().
5716+
plt.draw() # Trigger _apply_aspect().
57175717
assert axs[0].get_xlim() != axs[1].get_xlim()
57185718
assert axs[0].get_ylim() == axs[1].get_ylim()
57195719
fig_aspect = fig.bbox_inches.height / fig.bbox_inches.width

lib/mpl_toolkits/axes_grid1/parasite_axes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,13 @@ def draw(self, renderer):
126126
if locator:
127127
pos = locator(self, renderer)
128128
self.set_position(pos, which="active")
129-
self.apply_aspect(pos)
129+
self._apply_aspect(pos)
130130
else:
131-
self.apply_aspect()
131+
self._apply_aspect()
132132

133133
rect = self.get_position()
134134
for ax in self.parasites:
135-
ax.apply_aspect(rect)
135+
ax._apply_aspect(rect)
136136
self._children.extend(ax.get_children())
137137

138138
super().draw(renderer)

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ def set_box_aspect(self, aspect, *, zoom=1):
386386
self._box_aspect = self._roll_to_vertical(aspect, reverse=True)
387387
self.stale = True
388388

389-
def apply_aspect(self, position=None):
389+
def _apply_aspect(self, position=None):
390390
if position is None:
391391
position = self.get_position(original=True)
392392

@@ -419,7 +419,7 @@ def draw(self, renderer):
419419
# it adjusts the view limits and the size of the bounding box
420420
# of the Axes
421421
locator = self.get_axes_locator()
422-
self.apply_aspect(locator(self, renderer) if locator else None)
422+
self._apply_aspect(locator(self, renderer) if locator else None)
423423

424424
# add the projection matrix to the renderer
425425
self.M = self.get_proj()

0 commit comments

Comments
 (0)