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

Skip to content

Backport PR #28342 on branch v3.9.x (DOC: Document the parameter *position* of apply_aspect() as internal) #28471

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1882,6 +1882,11 @@ def apply_aspect(self, position=None):
Parameters
----------
position : None or .Bbox

.. note::
This parameter exists for historic reasons and is considered
internal. End users should not use it.

If not ``None``, this defines the position of the
Axes within the figure as a Bbox. See `~.Axes.get_position`
for further details.
Expand All @@ -1892,6 +1897,10 @@ def apply_aspect(self, position=None):
to call it yourself if you need to update the Axes position and/or
view limits before the Figure is drawn.

An alternative with a broader scope is `.Figure.draw_without_rendering`,
which updates all stale components of a figure, not only the positioning /
view limits of a single Axes.

See Also
--------
matplotlib.axes.Axes.set_aspect
Expand All @@ -1900,6 +1909,24 @@ def apply_aspect(self, position=None):
Set how the Axes adjusts to achieve the required aspect ratio.
matplotlib.axes.Axes.set_anchor
Set the position in case of extra space.
matplotlib.figure.Figure.draw_without_rendering
Update all stale components of a figure.

Examples
--------
A typical usage example would be the following. `~.Axes.imshow` sets the
aspect to 1, but adapting the Axes position and extent to reflect this is
deferred until rendering for performance reasons. If you want to know the
Axes size before, you need to call `.apply_aspect` to get the correct
values.

>>> fig, ax = plt.subplots()
>>> ax.imshow(np.zeros((3, 3)))
>>> ax.bbox.width, ax.bbox.height
(496.0, 369.59999999999997)
>>> ax.apply_aspect()
>>> ax.bbox.width, ax.bbox.height
(369.59999999999997, 369.59999999999997)
"""
if position is None:
position = self.get_position(original=True)
Expand Down
Loading