MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / apply_aspect

Method apply_aspect

lib/matplotlib/axes/_base.py:1965–2127  ·  view source on GitHub ↗

Adjust the Axes for a specified data aspect ratio. Depending on `.get_adjustable` this will modify either the Axes box (position) or the view limits. In the former case, `~matplotlib.axes.Axes.get_anchor` will affect the position. Parameters -------

(self, position=None)

Source from the content-addressed store, hash-verified

1963 return ysize / xsize
1964
1965 def apply_aspect(self, position=None):
1966 """
1967 Adjust the Axes for a specified data aspect ratio.
1968
1969 Depending on `.get_adjustable` this will modify either the
1970 Axes box (position) or the view limits. In the former case,
1971 `~matplotlib.axes.Axes.get_anchor` will affect the position.
1972
1973 Parameters
1974 ----------
1975 position : None or .Bbox
1976
1977 .. note::
1978 This parameter exists for historic reasons and is considered
1979 internal. End users should not use it.
1980
1981 If not ``None``, this defines the position of the
1982 Axes within the figure as a Bbox. See `~.Axes.get_position`
1983 for further details.
1984
1985 Notes
1986 -----
1987 This is called automatically when each Axes is drawn. You may need
1988 to call it yourself if you need to update the Axes position and/or
1989 view limits before the Figure is drawn.
1990
1991 An alternative with a broader scope is `.Figure.draw_without_rendering`,
1992 which updates all stale components of a figure, not only the positioning /
1993 view limits of a single Axes.
1994
1995 See Also
1996 --------
1997 matplotlib.axes.Axes.set_aspect
1998 For a description of aspect ratio handling.
1999 matplotlib.axes.Axes.set_adjustable
2000 Set how the Axes adjusts to achieve the required aspect ratio.
2001 matplotlib.axes.Axes.set_anchor
2002 Set the position in case of extra space.
2003 matplotlib.figure.Figure.draw_without_rendering
2004 Update all stale components of a figure.
2005
2006 Examples
2007 --------
2008 A typical usage example would be the following. `~.Axes.imshow` sets the
2009 aspect to 1, but adapting the Axes position and extent to reflect this is
2010 deferred until rendering for performance reasons. If you want to know the
2011 Axes size before, you need to call `.apply_aspect` to get the correct
2012 values.
2013
2014 >>> fig, ax = plt.subplots()
2015 >>> ax.imshow(np.zeros((3, 3)))
2016 >>> ax.bbox.width, ax.bbox.height
2017 (496.0, 369.59999999999997)
2018 >>> ax.apply_aspect()
2019 >>> ax.bbox.width, ax.bbox.height
2020 (369.59999999999997, 369.59999999999997)
2021 """
2022 if position is None:

Callers 11

get_positionMethod · 0.95
drawMethod · 0.95
get_tightbboxMethod · 0.95
compress_fixed_aspectFunction · 0.45
_get_draw_artistsMethod · 0.45
adjust_bboxFunction · 0.45
indicate_insetMethod · 0.45
test_insetFunction · 0.45
test_zoom_insetFunction · 0.45

Calls 15

get_positionMethod · 0.95
get_aspectMethod · 0.95
_set_positionMethod · 0.95
get_data_ratioMethod · 0.95
get_anchorMethod · 0.95
get_xboundMethod · 0.95
get_yboundMethod · 0.95
set_yboundMethod · 0.95
set_xboundMethod · 0.95
unitMethod · 0.80
shrunk_to_aspectMethod · 0.80
anchoredMethod · 0.80

Tested by 3

test_insetFunction · 0.36
test_zoom_insetFunction · 0.36