Skip to content

Commit 01e6a47

Browse files
committed
Don't reshape offsets into the correct shape.
(Instead let invalid entries error.)
1 parent a4bd3ce commit 01e6a47

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

lib/matplotlib/collections.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def __init__(self,
145145
self._uniform_offsets = None
146146
self._offsets = np.array([[0, 0]], float)
147147
if offsets is not None:
148-
offsets = np.asanyarray(offsets).reshape((-1, 2))
148+
offsets = np.asanyarray(offsets, float)
149149
if transOffset is not None:
150150
self._offsets = offsets
151151
self._transOffset = transOffset
@@ -210,7 +210,6 @@ def get_datalim(self, transData):
210210
offsets = transOffset.transform_non_affine(offsets)
211211
transOffset = transOffset.get_affine()
212212

213-
offsets = np.asanyarray(offsets, float).reshape((-1, 2))
214213
if isinstance(offsets, np.ma.MaskedArray):
215214
offsets = offsets.filled(np.nan)
216215
# get_path_collection_extents handles nan but not masked arrays
@@ -244,14 +243,12 @@ def _prepare_points(self):
244243
xs, ys = vertices[:, 0], vertices[:, 1]
245244
xs = self.convert_xunits(xs)
246245
ys = self.convert_yunits(ys)
247-
paths.append(mpath.Path(list(zip(xs, ys)), path.codes))
246+
paths.append(mpath.Path(np.column_stack([xs, ys]), path.codes))
248247

249248
if offsets.size > 0:
250249
xs = self.convert_xunits(offsets[:, 0])
251250
ys = self.convert_yunits(offsets[:, 1])
252-
offsets = list(zip(xs, ys))
253-
254-
offsets = np.asanyarray(offsets, float).reshape((-1, 2))
251+
offsets = np.column_stack([xs, ys])
255252

256253
if not transform.is_affine:
257254
paths = [transform.transform_path_non_affine(path)
@@ -431,7 +428,7 @@ def set_offsets(self, offsets):
431428
432429
ACCEPTS: float or sequence of floats
433430
"""
434-
offsets = np.asanyarray(offsets, float).reshape((-1, 2))
431+
offsets = np.asanyarray(offsets, float)
435432
#This decision is based on how they are initialized above
436433
if self._uniform_offsets is None:
437434
self._offsets = offsets
@@ -1881,17 +1878,12 @@ def draw(self, renderer):
18811878
if len(self._offsets):
18821879
xs = self.convert_xunits(self._offsets[:, 0])
18831880
ys = self.convert_yunits(self._offsets[:, 1])
1884-
offsets = list(zip(xs, ys))
1885-
1886-
offsets = np.asarray(offsets, float).reshape((-1, 2))
1881+
offsets = np.column_stack([xs, ys])
18871882

18881883
self.update_scalarmappable()
18891884

18901885
if not transform.is_affine:
1891-
coordinates = self._coordinates.reshape(
1892-
(self._coordinates.shape[0] *
1893-
self._coordinates.shape[1],
1894-
2))
1886+
coordinates = self._coordinates.reshape((-1, 2))
18951887
coordinates = transform.transform(coordinates)
18961888
coordinates = coordinates.reshape(self._coordinates.shape)
18971889
transform = transforms.IdentityTransform()

0 commit comments

Comments
 (0)