diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 63b16c311810..a420599ceb40 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -50,16 +50,14 @@ def _make_inset_locator(bounds, trans, parent): location for the axes in the transform given by *trans* on the *parent*. """ - _bounds = mtransforms.Bbox.from_bounds(*bounds) - _trans = trans - _parent = parent + bbox = mtransforms.Bbox.from_bounds(*bounds) def inset_locator(ax, renderer): - bbox = _bounds - bb = mtransforms.TransformedBbox(bbox, _trans) - tr = _parent.figure.transFigure.inverted() - bb = mtransforms.TransformedBbox(bb, tr) - return bb + # Subtracting transFigure will typically rely on inverted(), freezing + # the transform; thus, this needs to be delayed until draw time as + # transFigure may otherwise change after this is evaluated. + return mtransforms.TransformedBbox( + bbox, trans - parent.figure.transFigure) return inset_locator diff --git a/lib/matplotlib/axes/_secondary_axes.py b/lib/matplotlib/axes/_secondary_axes.py index 39b840833345..eb8d0ede9039 100644 --- a/lib/matplotlib/axes/_secondary_axes.py +++ b/lib/matplotlib/axes/_secondary_axes.py @@ -4,36 +4,10 @@ import matplotlib.docstring as docstring import matplotlib.ticker as mticker import matplotlib.transforms as mtransforms +from matplotlib.axes import _axes from matplotlib.axes._base import _AxesBase -def _make_secondary_locator(rect, parent): - """ - Helper function to locate the secondary axes. - - A locator gets used in `Axes.set_aspect` to override the default - locations... It is a function that takes an axes object and - a renderer and tells `set_aspect` where it is to be placed. - - This locator make the transform be in axes-relative co-coordinates - because that is how we specify the "location" of the secondary axes. - - Here *rect* is a rectangle [l, b, w, h] that specifies the - location for the axes in the transform given by *trans* on the - *parent*. - """ - _rect = mtransforms.Bbox.from_bounds(*rect) - def secondary_locator(ax, renderer): - # delay evaluating transform until draw time because the - # parent transform may have changed (i.e. if window reesized) - bb = mtransforms.TransformedBbox(_rect, parent.transAxes) - tr = parent.figure.transFigure.inverted() - bb = mtransforms.TransformedBbox(bb, tr) - return bb - - return secondary_locator - - class SecondaryAxis(_AxesBase): """ General class to hold a Secondary_X/Yaxis. @@ -137,11 +111,14 @@ def set_location(self, location): self._loc = location if self._orientation == 'x': + # An x-secondary axes is like an inset axes from x = 0 to x = 1 and + # from y = pos to y = pos + eps, in the parent's transAxes coords. bounds = [0, self._pos, 1., 1e-10] else: bounds = [self._pos, 0, 1e-10, 1] - secondary_locator = _make_secondary_locator(bounds, self._parent) + secondary_locator = _axes._make_inset_locator( + bounds, self._parent.transAxes, self._parent) # this locator lets the axes move in the parent axes coordinates. # so it never needs to know where the parent is explicitly in