Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4fe22e1

Browse filesBrowse files
authored
Merge pull request #9232 from anntzer/fix-collections-offsets
Fix passing shape (2,) input to Collections.set_offsets.
2 parents affc5c6 + c5170ec commit 4fe22e1
Copy full SHA for 4fe22e1

File tree

Expand file treeCollapse file tree

1 file changed

+10
-7
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+10
-7
lines changed

‎lib/matplotlib/collections.py

Copy file name to clipboardExpand all lines: lib/matplotlib/collections.py
+10-7Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.