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

Skip to content

Commit dbd1f4e

Browse files
committed
DOC: Document the parameter *position* of apply_aspect() as internal
Superseeds #23629. It is somewhat surprising that "_apply_aspect" takes an optional position as input, which seems more functionality than what the name suggests. The parameter was introduced in 66290aa. Generally, applying an aspect will modify the size and position of an Axes. The fact that position is updated anyway was used to funnel additional position information from a layout into the already existing positioning code. Deprecating and removing the parameter would be a medium compatibility hassle. Therefore, I chose only to document the status quo and its intention, so that users are less surprised. See #23629 (comment)
1 parent 479bd7a commit dbd1f4e

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1881,6 +1881,11 @@ def apply_aspect(self, position=None):
18811881
Parameters
18821882
----------
18831883
position : None or .Bbox
1884+
1885+
.. note::
1886+
This parameter exists for historic reasons and is considered
1887+
internal. End users should not use it.
1888+
18841889
If not ``None``, this defines the position of the
18851890
Axes within the figure as a Bbox. See `~.Axes.get_position`
18861891
for further details.
@@ -1891,6 +1896,10 @@ def apply_aspect(self, position=None):
18911896
to call it yourself if you need to update the Axes position and/or
18921897
view limits before the Figure is drawn.
18931898
1899+
An alternative with a broader scope is `.Figure.draw_without_rendering`,
1900+
which updates all stale components of a figure, not only the positioning /
1901+
view limits of a single Axes.
1902+
18941903
See Also
18951904
--------
18961905
matplotlib.axes.Axes.set_aspect
@@ -1899,6 +1908,23 @@ def apply_aspect(self, position=None):
18991908
Set how the Axes adjusts to achieve the required aspect ratio.
19001909
matplotlib.axes.Axes.set_anchor
19011910
Set the position in case of extra space.
1911+
matplotlib.figure.Figure.draw_without_rendering
1912+
Update all stale components of a figure.
1913+
1914+
Examples
1915+
--------
1916+
A typical usage example would be the following. `~.Axes.imshow` sets the
1917+
aspect to 1, but the Axes will only be updated for that on rendering.
1918+
If you need to know the Axes size before, you need to call `.apply_aspect`
1919+
to get the correct values.
1920+
1921+
>>> fig, ax = plt.subplots()
1922+
>>> ax.imshow(np.zeros((3, 3)))
1923+
>>> ax.bbox.width, ax.bbox.height
1924+
(496.0, 369.59999999999997)
1925+
>>> ax.apply_aspect()
1926+
>>> ax.bbox.width, ax.bbox.height
1927+
(369.59999999999997, 369.59999999999997)
19021928
"""
19031929
if position is None:
19041930
position = self.get_position(original=True)

0 commit comments

Comments
 (0)