Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cb578e4

Browse files
committed
Merge pull request #431 from efiring/collection_log_offset
collections: fix bug in scatter with log scale; handle masked offsets
2 parents fca4baf + 8360126 commit cb578e4

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

lib/matplotlib/collections.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def __init__(self,
101101
# Force _offsets to be Nx2
102102
self._offsets.shape = (0, 2)
103103
if offsets is not None:
104-
offsets = np.asarray(offsets)
104+
offsets = np.asanyarray(offsets)
105105
offsets.shape = (-1, 2) # Make it Nx2
106106
if transOffset is not None:
107107
self._offsets = offsets
@@ -160,7 +160,10 @@ def get_datalim(self, transData):
160160
offsets = transOffset.transform_non_affine(offsets)
161161
transOffset = transOffset.get_affine()
162162

163-
offsets = np.asarray(offsets, np.float_)
163+
offsets = np.asanyarray(offsets, np.float_)
164+
if np.ma.isMaskedArray(offsets):
165+
offsets = offsets.filled(np.nan)
166+
# get_path_collection_extents handles nan but not masked arrays
164167
offsets.shape = (-1, 2) # Make it Nx2
165168

166169
result = mpath.get_path_collection_extents(
@@ -198,16 +201,22 @@ def _prepare_points(self):
198201
ys = self.convert_yunits(offsets[:,1])
199202
offsets = zip(xs, ys)
200203

201-
offsets = np.asarray(offsets, np.float_)
204+
offsets = np.asanyarray(offsets, np.float_)
202205
offsets.shape = (-1, 2) # Make it Nx2
203206

204207
if not transform.is_affine:
205208
paths = [transform.transform_path_non_affine(path) for path in paths]
206209
transform = transform.get_affine()
207210
if not transOffset.is_affine :
208211
offsets = transOffset.transform_non_affine(offsets)
212+
# This might have changed an ndarray into a masked array.
209213
transOffset = transOffset.get_affine()
210214

215+
if np.ma.isMaskedArray(offsets):
216+
offsets = offsets.filled(np.nan)
217+
# Changing from a masked array to nan-filled ndarray
218+
# is probably most efficient at this point.
219+
211220
return transform, transOffset, offsets, paths
212221

213222
@allow_rasterization
@@ -289,7 +298,7 @@ def set_offsets(self, offsets):
289298
290299
ACCEPTS: float or sequence of floats
291300
"""
292-
offsets = np.asarray(offsets, np.float_)
301+
offsets = np.asanyarray(offsets, np.float_)
293302
offsets.shape = (-1, 2) # Make it Nx2
294303
#This decision is based on how they are initialized above
295304
if self._uniform_offsets is None:
@@ -588,13 +597,13 @@ def __init__(self, paths, sizes=None, **kwargs):
588597

589598
def set_paths(self, paths):
590599
self._paths = paths
591-
600+
592601
def get_paths(self):
593602
return self._paths
594-
603+
595604
def get_sizes(self):
596605
return self._sizes
597-
606+
598607
@allow_rasterization
599608
def draw(self, renderer):
600609
if self._sizes is not None:

0 commit comments

Comments
 (0)