Skip to content

Commit 28d03bf

Browse files
Code review updates
1 parent cb0a07c commit 28d03bf

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

lib/matplotlib/transforms.py

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -908,23 +908,19 @@ def _calc_extents_from_path(self, path, ignore, updatex=True, updatey=True):
908908
points = self._points.copy()
909909
minpos = self._minpos.copy()
910910

911-
if updatex and updatey:
912-
where = (np.isfinite(path.vertices[..., 0])
913-
& np.isfinite(path.vertices[..., 1]))
914-
elif updatex:
915-
where = np.isfinite(path.vertices[..., 0])
916-
elif updatey:
917-
where = np.isfinite(path.vertices[..., 1])
918-
else:
911+
if not (updatex or updatey):
919912
return points, minpos, False
920913

914+
valid_points = (np.isfinite(path.vertices[..., 0])
915+
& np.isfinite(path.vertices[..., 1]))
916+
921917
if updatex:
922-
x = path.vertices[..., 0][where]
918+
x = path.vertices[..., 0][valid_points]
923919
points[0, 0] = min(points[0, 0], np.min(x, initial=np.inf))
924920
points[1, 0] = max(points[1, 0], np.max(x, initial=-np.inf))
925921
minpos[0] = min(minpos[0], np.min(x[x > 0], initial=np.inf))
926922
if updatey:
927-
y = path.vertices[..., 1][where]
923+
y = path.vertices[..., 1][valid_points]
928924
points[0, 1] = min(points[0, 1], np.min(y, initial=np.inf))
929925
points[1, 1] = max(points[1, 1], np.max(y, initial=-np.inf))
930926
minpos[1] = min(minpos[1], np.min(y[y > 0], initial=np.inf))
@@ -949,9 +945,7 @@ def update_from_data_x(self, x, ignore=None):
949945
- When ``None``, use the last value passed to :meth:`ignore`.
950946
"""
951947
x = np.ravel(x)
952-
xy = np.empty((x.size, 2), dtype=x.dtype)
953-
xy[:, 0] = x
954-
self.update_from_data_xy(xy, ignore=ignore, updatey=False)
948+
self.update_from_data_xy(np.array([x, x]).T, ignore=ignore, updatey=False)
955949

956950
def update_from_data_y(self, y, ignore=None):
957951
"""
@@ -969,9 +963,7 @@ def update_from_data_y(self, y, ignore=None):
969963
- When ``None``, use the last value passed to :meth:`ignore`.
970964
"""
971965
y = np.ravel(y)
972-
xy = np.empty((y.size, 2), dtype=y.dtype)
973-
xy[:, 1] = y
974-
self.update_from_data_xy(xy, ignore=ignore, updatex=False)
966+
self.update_from_data_xy(np.array([y, y]).T, ignore=ignore, updatex=False)
975967

976968
def update_from_data_xy(self, xy, ignore=None, updatex=True, updatey=True):
977969
"""

0 commit comments

Comments
 (0)