Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d9507a2

Browse files
authored
Merge pull request #7786 from anntzer/dont-reshape-offsets
Don't reshape offsets into the correct shape.
2 parents 98ce210 + ca4ddac commit d9507a2

File tree

3 files changed

+8
-16
lines changed

3 files changed

+8
-16
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4041,7 +4041,7 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
40414041
edgecolors = 'face'
40424042
linewidths = rcParams['lines.linewidth']
40434043

4044-
offsets = np.dstack((x, y))
4044+
offsets = np.column_stack([x, y])
40454045

40464046
collection = mcoll.PathCollection(
40474047
(path,), scales,

lib/matplotlib/collections.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def __init__(self,
146146
self._uniform_offsets = None
147147
self._offsets = np.array([[0, 0]], float)
148148
if offsets is not None:
149-
offsets = np.asanyarray(offsets).reshape((-1, 2))
149+
offsets = np.asanyarray(offsets, float)
150150
if transOffset is not None:
151151
self._offsets = offsets
152152
self._transOffset = transOffset
@@ -186,7 +186,6 @@ def get_datalim(self, transData):
186186
offsets = transOffset.transform_non_affine(offsets)
187187
transOffset = transOffset.get_affine()
188188

189-
offsets = np.asanyarray(offsets, float).reshape((-1, 2))
190189
if isinstance(offsets, np.ma.MaskedArray):
191190
offsets = offsets.filled(np.nan)
192191
# get_path_collection_extents handles nan but not masked arrays
@@ -220,14 +219,12 @@ def _prepare_points(self):
220219
xs, ys = vertices[:, 0], vertices[:, 1]
221220
xs = self.convert_xunits(xs)
222221
ys = self.convert_yunits(ys)
223-
paths.append(mpath.Path(list(zip(xs, ys)), path.codes))
222+
paths.append(mpath.Path(np.column_stack([xs, ys]), path.codes))
224223

225224
if offsets.size > 0:
226225
xs = self.convert_xunits(offsets[:, 0])
227226
ys = self.convert_yunits(offsets[:, 1])
228-
offsets = list(zip(xs, ys))
229-
230-
offsets = np.asanyarray(offsets, float).reshape((-1, 2))
227+
offsets = np.column_stack([xs, ys])
231228

232229
if not transform.is_affine:
233230
paths = [transform.transform_path_non_affine(path)
@@ -413,7 +410,7 @@ def set_offsets(self, offsets):
413410
414411
ACCEPTS: float or sequence of floats
415412
"""
416-
offsets = np.asanyarray(offsets, float).reshape((-1, 2))
413+
offsets = np.asanyarray(offsets, float)
417414
#This decision is based on how they are initialized above
418415
if self._uniform_offsets is None:
419416
self._offsets = offsets
@@ -1869,17 +1866,12 @@ def draw(self, renderer):
18691866
if len(self._offsets):
18701867
xs = self.convert_xunits(self._offsets[:, 0])
18711868
ys = self.convert_yunits(self._offsets[:, 1])
1872-
offsets = list(zip(xs, ys))
1873-
1874-
offsets = np.asarray(offsets, float).reshape((-1, 2))
1869+
offsets = np.column_stack([xs, ys])
18751870

18761871
self.update_scalarmappable()
18771872

18781873
if not transform.is_affine:
1879-
coordinates = self._coordinates.reshape(
1880-
(self._coordinates.shape[0] *
1881-
self._coordinates.shape[1],
1882-
2))
1874+
coordinates = self._coordinates.reshape((-1, 2))
18831875
coordinates = transform.transform(coordinates)
18841876
coordinates = coordinates.reshape(self._coordinates.shape)
18851877
transform = transforms.IdentityTransform()

lib/matplotlib/tests/test_collections.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ def test_regularpolycollection_rotate():
516516
for xy, alpha in zip(xy_points, rotations):
517517
col = mcollections.RegularPolyCollection(
518518
4, sizes=(100,), rotation=alpha,
519-
offsets=xy, transOffset=ax.transData)
519+
offsets=[xy], transOffset=ax.transData)
520520
ax.add_collection(col, autolim=True)
521521
ax.autoscale_view()
522522

0 commit comments

Comments
 (0)