Skip to content

Commit dfe72ed

Browse files
Vectorize bounding box limits updates
1 parent 042d068 commit dfe72ed

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

lib/matplotlib/transforms.py

+29-5
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@
4646
from numpy.linalg import inv
4747

4848
from matplotlib import _api
49-
from matplotlib._path import (
50-
affine_transform, count_bboxes_overlapping_bbox, update_path_extents)
49+
from matplotlib._path import affine_transform, count_bboxes_overlapping_bbox
5150
from .path import Path
5251

5352
DEBUG = False
@@ -868,10 +867,35 @@ def update_from_path(self, path, ignore=None, updatex=True, updatey=True):
868867
if path.vertices.size == 0:
869868
return
870869

871-
points, minpos, changed = update_path_extents(
872-
path, None, self._points, self._minpos, ignore)
870+
if ignore:
871+
points = np.array([[np.inf, np.inf], [-np.inf, -np.inf]])
872+
minpos = np.array([np.inf, np.inf])
873+
else:
874+
points = self._points.copy()
875+
minpos = self._minpos.copy()
876+
877+
if updatex and updatey:
878+
where = (np.isfinite(path.vertices[..., 0])
879+
& np.isfinite(path.vertices[..., 1]))
880+
elif updatex:
881+
where = np.isfinite(path.vertices[..., 0])
882+
elif updatey:
883+
where = np.isfinite(path.vertices[..., 1])
884+
else:
885+
return
873886

874-
if changed:
887+
if updatex:
888+
x = path.vertices[..., 0][where]
889+
points[0, 0] = min(points[0, 0], np.min(x, initial=np.inf))
890+
points[1, 0] = max(points[1, 0], np.max(x, initial=-np.inf))
891+
minpos[0] = min(minpos[0], np.min(x[x > 0], initial=np.inf))
892+
if updatey:
893+
y = path.vertices[..., 1][where]
894+
points[0, 1] = min(points[0, 1], np.min(y, initial=np.inf))
895+
points[1, 1] = max(points[1, 1], np.max(y, initial=-np.inf))
896+
minpos[1] = min(minpos[1], np.min(y[y > 0], initial=np.inf))
897+
898+
if np.any(points != self._points) or np.any(minpos != self._minpos):
875899
self.invalidate()
876900
if updatex:
877901
self._points[:, 0] = points[:, 0]

0 commit comments

Comments
 (0)