Skip to content

Commit e624d6a

Browse files
authored
Merge pull request #13381 from anntzer/unflatten
Avoid unneeded copies from flatten().
2 parents db33830 + 1ebf1c3 commit e624d6a

File tree

2 files changed

+14
-20
lines changed

2 files changed

+14
-20
lines changed

lib/matplotlib/transforms.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ def __array__(self, *args, **kwargs):
282282

283283
def is_unit(self):
284284
"""Return whether this is the unit box (from (0, 0) to (1, 1))."""
285-
return list(self.get_points().flatten()) == [0., 0., 1., 1.]
285+
return self.get_points().tolist() == [[0., 0.], [1., 1.]]
286286

287287
@property
288288
def x0(self):
@@ -413,13 +413,13 @@ def size(self):
413413
@property
414414
def bounds(self):
415415
"""Return (:attr:`x0`, :attr:`y0`, :attr:`width`, :attr:`height`)."""
416-
x0, y0, x1, y1 = self.get_points().flatten()
416+
(x0, y0), (x1, y1) = self.get_points()
417417
return (x0, y0, x1 - x0, y1 - y0)
418418

419419
@property
420420
def extents(self):
421421
"""Return (:attr:`x0`, :attr:`y0`, :attr:`x1`, :attr:`y1`)."""
422-
return self.get_points().flatten().copy()
422+
return self.get_points().flatten() # flatten returns a copy.
423423

424424
def get_points(self):
425425
raise NotImplementedError
@@ -1758,10 +1758,10 @@ def is_separable(self):
17581758

17591759
def to_values(self):
17601760
"""
1761-
Return the values of the matrix as a sequence (a,b,c,d,e,f)
1761+
Return the values of the matrix as an ``(a, b, c, d, e, f)`` tuple.
17621762
"""
17631763
mtx = self.get_matrix()
1764-
return tuple(mtx[:2].swapaxes(0, 1).flatten())
1764+
return tuple(mtx[:2].swapaxes(0, 1).flat)
17651765

17661766
@staticmethod
17671767
def matrix_from_values(a, b, c, d, e, f):

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -490,22 +490,16 @@ def autoscale(self, enable=True, axis='both', tight=None):
490490
scalez=scalez)
491491

492492
def auto_scale_xyz(self, X, Y, Z=None, had_data=None):
493-
x, y, z = map(np.asarray, (X, Y, Z))
494-
try:
495-
x, y = x.flatten(), y.flatten()
496-
if Z is not None:
497-
z = z.flatten()
498-
except AttributeError:
499-
raise
500-
501-
# This updates the bounding boxes as to keep a record as
502-
# to what the minimum sized rectangular volume holds the
503-
# data.
504-
self.xy_dataLim.update_from_data_xy(np.array([x, y]).T, not had_data)
505-
if z is not None:
493+
# This updates the bounding boxes as to keep a record as to what the
494+
# minimum sized rectangular volume holds the data.
495+
X = np.reshape(X, -1)
496+
Y = np.reshape(Y, -1)
497+
self.xy_dataLim.update_from_data_xy(
498+
np.column_stack([X, Y]), not had_data)
499+
if Z is not None:
500+
Z = np.reshape(Z, -1)
506501
self.zz_dataLim.update_from_data_xy(
507-
np.array([z, z]).T, not had_data)
508-
502+
np.column_stack([Z, Z]), not had_data)
509503
# Let autoscale_view figure out how to use this data.
510504
self.autoscale_view()
511505

0 commit comments

Comments
 (0)