From c5170ec00f6b7b725ad63e68f95f12fd5666efcd Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Tue, 26 Sep 2017 02:07:34 -0700 Subject: [PATCH] Fix passing shape (2,) input to Collections.set_offsets. The logic with uniform_offsets seems a bit crazy but let's just reproduce it for now... --- lib/matplotlib/collections.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/matplotlib/collections.py b/lib/matplotlib/collections.py index 3acbaeceefbe..f660fd1eb67b 100644 --- a/lib/matplotlib/collections.py +++ b/lib/matplotlib/collections.py @@ -143,10 +143,13 @@ def __init__(self, self.set_offset_position(offset_position) self.set_zorder(zorder) + self._offsets = np.zeros((1, 2)) self._uniform_offsets = None - self._offsets = np.array([[0, 0]], float) if offsets is not None: offsets = np.asanyarray(offsets, float) + # Broadcast (2,) -> (1, 2) but nothing else. + if offsets.shape == (2,): + offsets = offsets[None, :] if transOffset is not None: self._offsets = offsets self._transOffset = transOffset @@ -400,7 +403,7 @@ def set_hatch(self, hatch): self.stale = True def get_hatch(self): - 'Return the current hatching pattern' + """Return the current hatching pattern.""" return self._hatch def set_offsets(self, offsets): @@ -411,7 +414,9 @@ def set_offsets(self, offsets): ACCEPTS: float or sequence of floats """ offsets = np.asanyarray(offsets, float) - #This decision is based on how they are initialized above + if offsets.shape == (2,): # Broadcast (2,) -> (1, 2) but nothing else. + offsets = offsets[None, :] + # This decision is based on how they are initialized above in __init__. if self._uniform_offsets is None: self._offsets = offsets else: @@ -419,10 +424,8 @@ def set_offsets(self, offsets): self.stale = True def get_offsets(self): - """ - Return the offsets for the collection. - """ - #This decision is based on how they are initialized above in __init__() + """Return the offsets for the collection.""" + # This decision is based on how they are initialized above in __init__. if self._uniform_offsets is None: return self._offsets else: