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 9ccda79

Browse filesBrowse files
committed
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 4792425 commit 9ccda79
Copy full SHA for 9ccda79

File tree

Expand file treeCollapse file tree

1 file changed

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

1 file changed

+10
-10
lines changed

‎lib/matplotlib/collections.py

Copy file name to clipboardExpand all lines: lib/matplotlib/collections.py
+10-10Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,15 @@ 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:
149-
offsets = np.asanyarray(offsets, float)
150149
if transOffset is not None:
151-
self._offsets = offsets
152150
self._transOffset = transOffset
153151
else:
154-
self._uniform_offsets = offsets
152+
# Just a placeholder to trigger the right path in set_offsets.
153+
self._uniform_offsets = object()
154+
self.set_offsets(offsets)
155155

156156
self._path_effects = None
157157
self.update(kwargs)
@@ -400,7 +400,7 @@ def set_hatch(self, hatch):
400400
self.stale = True
401401

402402
def get_hatch(self):
403-
'Return the current hatching pattern'
403+
"""Return the current hatching pattern."""
404404
return self._hatch
405405

406406
def set_offsets(self, offsets):
@@ -411,18 +411,18 @@ def set_offsets(self, offsets):
411411
ACCEPTS: float or sequence of floats
412412
"""
413413
offsets = np.asanyarray(offsets, float)
414-
#This decision is based on how they are initialized above
414+
if offsets.shape == (2,): # Broadcast (2,) -> (1, 2) but nothing else.
415+
offsets = offsets[None, :]
416+
# This decision is based on how they are initialized above in __init__.
415417
if self._uniform_offsets is None:
416418
self._offsets = offsets
417419
else:
418420
self._uniform_offsets = offsets
419421
self.stale = True
420422

421423
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__()
424+
"""Return the offsets for the collection."""
425+
# This decision is based on how they are initialized above in __init__.
426426
if self._uniform_offsets is None:
427427
return self._offsets
428428
else:

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.