diff --git a/lib/matplotlib/transforms.py b/lib/matplotlib/transforms.py index db216fcb8433..2cca56f04457 100644 --- a/lib/matplotlib/transforms.py +++ b/lib/matplotlib/transforms.py @@ -867,43 +867,9 @@ def update_from_path(self, path, ignore=None, updatex=True, updatey=True): if ignore is None: ignore = self._ignore - if path.vertices.size == 0: + if path.vertices.size == 0 or not (updatex or updatey): return - points, minpos, changed = self._calc_extents_from_path(path, ignore, - updatex, updatey) - - if changed: - self.invalidate() - if updatex: - self._points[:, 0] = points[:, 0] - self._minpos[0] = minpos[0] - if updatey: - self._points[:, 1] = points[:, 1] - self._minpos[1] = minpos[1] - - def _calc_extents_from_path(self, path, ignore, updatex=True, updatey=True): - """ - Calculate the new bounds and minimum positive values for a `Bbox` from - the path. - - Parameters - ---------- - path : `~matplotlib.path.Path` - ignore : bool - - When ``True``, ignore the existing bounds of the `Bbox`. - - When ``False``, include the existing bounds of the `Bbox`. - updatex : bool - When ``True``, update the x-values. - updatey : bool - When ``True``, update the y-values. - - Returns - ------- - points : (2, 2) array - minpos : (2,) array - changed : bool - """ if ignore: points = np.array([[np.inf, np.inf], [-np.inf, -np.inf]]) minpos = np.array([np.inf, np.inf]) @@ -911,9 +877,6 @@ def _calc_extents_from_path(self, path, ignore, updatex=True, updatey=True): points = self._points.copy() minpos = self._minpos.copy() - if not (updatex or updatey): - return points, minpos, False - valid_points = (np.isfinite(path.vertices[..., 0]) & np.isfinite(path.vertices[..., 1])) @@ -928,9 +891,14 @@ def _calc_extents_from_path(self, path, ignore, updatex=True, updatey=True): points[1, 1] = max(points[1, 1], np.max(y, initial=-np.inf)) minpos[1] = min(minpos[1], np.min(y[y > 0], initial=np.inf)) - changed = np.any(points != self._points) or np.any(minpos != self._minpos) - - return points, minpos, changed + if np.any(points != self._points) or np.any(minpos != self._minpos): + self.invalidate() + if updatex: + self._points[:, 0] = points[:, 0] + self._minpos[0] = minpos[0] + if updatey: + self._points[:, 1] = points[:, 1] + self._minpos[1] = minpos[1] def update_from_data_x(self, x, ignore=None): """