Skip to content

Commit 6cca7ba

Browse files
authored
Merge pull request #29831 from anntzer/cefp
Inline _calc_extents_from_path.
2 parents 77993d5 + 4d25db2 commit 6cca7ba

File tree

1 file changed

+9
-41
lines changed

1 file changed

+9
-41
lines changed

lib/matplotlib/transforms.py

+9-41
Original file line numberDiff line numberDiff line change
@@ -867,53 +867,16 @@ def update_from_path(self, path, ignore=None, updatex=True, updatey=True):
867867
if ignore is None:
868868
ignore = self._ignore
869869

870-
if path.vertices.size == 0:
870+
if path.vertices.size == 0 or not (updatex or updatey):
871871
return
872872

873-
points, minpos, changed = self._calc_extents_from_path(path, ignore,
874-
updatex, updatey)
875-
876-
if changed:
877-
self.invalidate()
878-
if updatex:
879-
self._points[:, 0] = points[:, 0]
880-
self._minpos[0] = minpos[0]
881-
if updatey:
882-
self._points[:, 1] = points[:, 1]
883-
self._minpos[1] = minpos[1]
884-
885-
def _calc_extents_from_path(self, path, ignore, updatex=True, updatey=True):
886-
"""
887-
Calculate the new bounds and minimum positive values for a `Bbox` from
888-
the path.
889-
890-
Parameters
891-
----------
892-
path : `~matplotlib.path.Path`
893-
ignore : bool
894-
- When ``True``, ignore the existing bounds of the `Bbox`.
895-
- When ``False``, include the existing bounds of the `Bbox`.
896-
updatex : bool
897-
When ``True``, update the x-values.
898-
updatey : bool
899-
When ``True``, update the y-values.
900-
901-
Returns
902-
-------
903-
points : (2, 2) array
904-
minpos : (2,) array
905-
changed : bool
906-
"""
907873
if ignore:
908874
points = np.array([[np.inf, np.inf], [-np.inf, -np.inf]])
909875
minpos = np.array([np.inf, np.inf])
910876
else:
911877
points = self._points.copy()
912878
minpos = self._minpos.copy()
913879

914-
if not (updatex or updatey):
915-
return points, minpos, False
916-
917880
valid_points = (np.isfinite(path.vertices[..., 0])
918881
& np.isfinite(path.vertices[..., 1]))
919882

@@ -928,9 +891,14 @@ def _calc_extents_from_path(self, path, ignore, updatex=True, updatey=True):
928891
points[1, 1] = max(points[1, 1], np.max(y, initial=-np.inf))
929892
minpos[1] = min(minpos[1], np.min(y[y > 0], initial=np.inf))
930893

931-
changed = np.any(points != self._points) or np.any(minpos != self._minpos)
932-
933-
return points, minpos, changed
894+
if np.any(points != self._points) or np.any(minpos != self._minpos):
895+
self.invalidate()
896+
if updatex:
897+
self._points[:, 0] = points[:, 0]
898+
self._minpos[0] = minpos[0]
899+
if updatey:
900+
self._points[:, 1] = points[:, 1]
901+
self._minpos[1] = minpos[1]
934902

935903
def update_from_data_x(self, x, ignore=None):
936904
"""

0 commit comments

Comments
 (0)