Skip to content

Commit c5170ec

Browse files
anntzertacaswell
authored andcommitted
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...
1 parent affc5c6 commit c5170ec

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

lib/matplotlib/collections.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,13 @@ def __init__(self,
143143
self.set_offset_position(offset_position)
144144
self.set_zorder(zorder)
145145

146+
self._offsets = np.zeros((1, 2))
146147
self._uniform_offsets = None
147-
self._offsets = np.array([[0, 0]], float)
148148
if offsets is not None:
149149
offsets = np.asanyarray(offsets, float)
150+
# Broadcast (2,) -> (1, 2) but nothing else.
151+
if offsets.shape == (2,):
152+
offsets = offsets[None, :]
150153
if transOffset is not None:
151154
self._offsets = offsets
152155
self._transOffset = transOffset
@@ -400,7 +403,7 @@ def set_hatch(self, hatch):
400403
self.stale = True
401404

402405
def get_hatch(self):
403-
'Return the current hatching pattern'
406+
"""Return the current hatching pattern."""
404407
return self._hatch
405408

406409
def set_offsets(self, offsets):
@@ -411,18 +414,18 @@ def set_offsets(self, offsets):
411414
ACCEPTS: float or sequence of floats
412415
"""
413416
offsets = np.asanyarray(offsets, float)
414-
#This decision is based on how they are initialized above
417+
if offsets.shape == (2,): # Broadcast (2,) -> (1, 2) but nothing else.
418+
offsets = offsets[None, :]
419+
# This decision is based on how they are initialized above in __init__.
415420
if self._uniform_offsets is None:
416421
self._offsets = offsets
417422
else:
418423
self._uniform_offsets = offsets
419424
self.stale = True
420425

421426
def get_offsets(self):
422-
"""
423-
Return the offsets for the collection.
424-
"""
425-
#This decision is based on how they are initialized above in __init__()
427+
"""Return the offsets for the collection."""
428+
# This decision is based on how they are initialized above in __init__.
426429
if self._uniform_offsets is None:
427430
return self._offsets
428431
else:

0 commit comments

Comments
 (0)