From ca4ddacceb0eeda42c588d0f61d43c9aee085855 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Tue, 10 Jan 2017 08:08:07 -0800 Subject: [PATCH] Don't reshape offsets into the correct shape. (Instead let invalid entries error.) --- lib/matplotlib/axes/_axes.py | 2 +- lib/matplotlib/collections.py | 20 ++++++-------------- lib/matplotlib/tests/test_collections.py | 2 +- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 803d6c3d54c7..acad11762bc3 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -4023,7 +4023,7 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None, edgecolors = 'face' linewidths = rcParams['lines.linewidth'] - offsets = np.dstack((x, y)) + offsets = np.column_stack([x, y]) collection = mcoll.PathCollection( (path,), scales, diff --git a/lib/matplotlib/collections.py b/lib/matplotlib/collections.py index 37de14a7c804..ee1d0b1eed76 100644 --- a/lib/matplotlib/collections.py +++ b/lib/matplotlib/collections.py @@ -145,7 +145,7 @@ def __init__(self, self._uniform_offsets = None self._offsets = np.array([[0, 0]], float) if offsets is not None: - offsets = np.asanyarray(offsets).reshape((-1, 2)) + offsets = np.asanyarray(offsets, float) if transOffset is not None: self._offsets = offsets self._transOffset = transOffset @@ -210,7 +210,6 @@ def get_datalim(self, transData): offsets = transOffset.transform_non_affine(offsets) transOffset = transOffset.get_affine() - offsets = np.asanyarray(offsets, float).reshape((-1, 2)) if isinstance(offsets, np.ma.MaskedArray): offsets = offsets.filled(np.nan) # get_path_collection_extents handles nan but not masked arrays @@ -244,14 +243,12 @@ def _prepare_points(self): xs, ys = vertices[:, 0], vertices[:, 1] xs = self.convert_xunits(xs) ys = self.convert_yunits(ys) - paths.append(mpath.Path(list(zip(xs, ys)), path.codes)) + paths.append(mpath.Path(np.column_stack([xs, ys]), path.codes)) if offsets.size > 0: xs = self.convert_xunits(offsets[:, 0]) ys = self.convert_yunits(offsets[:, 1]) - offsets = list(zip(xs, ys)) - - offsets = np.asanyarray(offsets, float).reshape((-1, 2)) + offsets = np.column_stack([xs, ys]) if not transform.is_affine: paths = [transform.transform_path_non_affine(path) @@ -431,7 +428,7 @@ def set_offsets(self, offsets): ACCEPTS: float or sequence of floats """ - offsets = np.asanyarray(offsets, float).reshape((-1, 2)) + offsets = np.asanyarray(offsets, float) #This decision is based on how they are initialized above if self._uniform_offsets is None: self._offsets = offsets @@ -1881,17 +1878,12 @@ def draw(self, renderer): if len(self._offsets): xs = self.convert_xunits(self._offsets[:, 0]) ys = self.convert_yunits(self._offsets[:, 1]) - offsets = list(zip(xs, ys)) - - offsets = np.asarray(offsets, float).reshape((-1, 2)) + offsets = np.column_stack([xs, ys]) self.update_scalarmappable() if not transform.is_affine: - coordinates = self._coordinates.reshape( - (self._coordinates.shape[0] * - self._coordinates.shape[1], - 2)) + coordinates = self._coordinates.reshape((-1, 2)) coordinates = transform.transform(coordinates) coordinates = coordinates.reshape(self._coordinates.shape) transform = transforms.IdentityTransform() diff --git a/lib/matplotlib/tests/test_collections.py b/lib/matplotlib/tests/test_collections.py index e029b90cde0c..c4c69a435087 100644 --- a/lib/matplotlib/tests/test_collections.py +++ b/lib/matplotlib/tests/test_collections.py @@ -538,7 +538,7 @@ def test_regularpolycollection_rotate(): for xy, alpha in zip(xy_points, rotations): col = mcollections.RegularPolyCollection( 4, sizes=(100,), rotation=alpha, - offsets=xy, transOffset=ax.transData) + offsets=[xy], transOffset=ax.transData) ax.add_collection(col, autolim=True) ax.autoscale_view() pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy