@@ -61,7 +61,6 @@ class Collection(artist.Artist, cm.ScalarMappable):
61
61
mappable will be used to set the ``facecolors`` and ``edgecolors``,
62
62
ignoring those that were manually passed in.
63
63
"""
64
- _offsets = np .zeros ((0 , 2 ))
65
64
#: Either a list of 3x3 arrays or an Nx3x3 array (representing N
66
65
#: transforms), suitable for the `all_transforms` argument to
67
66
#: `~matplotlib.backend_bases.RendererBase.draw_path_collection`;
@@ -193,15 +192,11 @@ def __init__(self,
193
192
else :
194
193
self ._joinstyle = None
195
194
196
- # default to zeros
197
- self ._offsets = np .zeros ((1 , 2 ))
198
-
199
195
if offsets is not None :
200
196
offsets = np .asanyarray (offsets , float )
201
197
# Broadcast (2,) -> (1, 2) but nothing else.
202
198
if offsets .shape == (2 ,):
203
199
offsets = offsets [None , :]
204
- self ._offsets = offsets
205
200
elif transOffset is not None :
206
201
_api .warn_deprecated (
207
202
'3.5' ,
@@ -215,6 +210,7 @@ def __init__(self,
215
210
'explicitly.' )
216
211
transOffset = None
217
212
213
+ self ._offsets = offsets
218
214
self ._transOffset = transOffset
219
215
220
216
self ._path_effects = None
@@ -273,9 +269,12 @@ def get_datalim(self, transData):
273
269
# if there are offsets but in some coords other than data,
274
270
# then don't use them for autoscaling.
275
271
return transforms .Bbox .null ()
276
- offsets = self ._offsets
272
+ offsets = self .get_offsets ()
277
273
278
274
paths = self .get_paths ()
275
+ if not len (paths ):
276
+ # No paths to transform
277
+ return transforms .Bbox .null ()
279
278
280
279
if not transform .is_affine :
281
280
paths = [transform .transform_path_non_affine (p ) for p in paths ]
@@ -284,22 +283,22 @@ def get_datalim(self, transData):
284
283
# transforms.get_affine().contains_branch(transData). But later,
285
284
# be careful to only apply the affine part that remains.
286
285
287
- if isinstance (offsets , np .ma .MaskedArray ):
288
- offsets = offsets .filled (np .nan )
286
+ if any (transform .contains_branch_seperately (transData )):
287
+ if isinstance (offsets , np .ma .MaskedArray ):
288
+ offsets = offsets .filled (np .nan )
289
289
# get_path_collection_extents handles nan but not masked arrays
290
-
291
- if len (paths ) and len (offsets ):
292
- if any (transform .contains_branch_seperately (transData )):
293
- # collections that are just in data units (like quiver)
294
- # can properly have the axes limits set by their shape +
295
- # offset. LineCollections that have no offsets can
296
- # also use this algorithm (like streamplot).
297
- return mpath .get_path_collection_extents (
298
- transform .get_affine () - transData , paths ,
299
- self .get_transforms (),
300
- transOffset .transform_non_affine (offsets ),
301
- transOffset .get_affine ().frozen ())
302
-
290
+ # collections that are just in data units (like quiver)
291
+ # can properly have the axes limits set by their shape +
292
+ # offset. LineCollections that have no offsets can
293
+ # also use this algorithm (like streamplot).
294
+ return mpath .get_path_collection_extents (
295
+ transform .get_affine () - transData , paths ,
296
+ self .get_transforms (),
297
+ transOffset .transform_non_affine (offsets ),
298
+ transOffset .get_affine ().frozen ())
299
+
300
+ # NOTE: None is the default case where no offsets were passed in
301
+ if self ._offsets is not None :
303
302
# this is for collections that have their paths (shapes)
304
303
# in physical, axes-relative, or figure-relative units
305
304
# (i.e. like scatter). We can't uniquely set limits based on
@@ -325,7 +324,7 @@ def _prepare_points(self):
325
324
326
325
transform = self .get_transform ()
327
326
transOffset = self .get_offset_transform ()
328
- offsets = self ._offsets
327
+ offsets = self .get_offsets ()
329
328
paths = self .get_paths ()
330
329
331
330
if self .have_units ():
@@ -336,10 +335,9 @@ def _prepare_points(self):
336
335
xs = self .convert_xunits (xs )
337
336
ys = self .convert_yunits (ys )
338
337
paths .append (mpath .Path (np .column_stack ([xs , ys ]), path .codes ))
339
- if offsets .size :
340
- xs = self .convert_xunits (offsets [:, 0 ])
341
- ys = self .convert_yunits (offsets [:, 1 ])
342
- offsets = np .column_stack ([xs , ys ])
338
+ xs = self .convert_xunits (offsets [:, 0 ])
339
+ ys = self .convert_yunits (offsets [:, 1 ])
340
+ offsets = np .column_stack ([xs , ys ])
343
341
344
342
if not transform .is_affine :
345
343
paths = [transform .transform_path_non_affine (path )
@@ -569,7 +567,8 @@ def set_offsets(self, offsets):
569
567
570
568
def get_offsets (self ):
571
569
"""Return the offsets for the collection."""
572
- return self ._offsets
570
+ # Default to zeros in the no-offset (None) case
571
+ return np .zeros ((1 , 2 )) if self ._offsets is None else self ._offsets
573
572
574
573
def _get_default_linewidth (self ):
575
574
# This may be overridden in a subclass.
@@ -2166,13 +2165,12 @@ def draw(self, renderer):
2166
2165
renderer .open_group (self .__class__ .__name__ , self .get_gid ())
2167
2166
transform = self .get_transform ()
2168
2167
transOffset = self .get_offset_transform ()
2169
- offsets = self ._offsets
2168
+ offsets = self .get_offsets ()
2170
2169
2171
2170
if self .have_units ():
2172
- if len (self ._offsets ):
2173
- xs = self .convert_xunits (self ._offsets [:, 0 ])
2174
- ys = self .convert_yunits (self ._offsets [:, 1 ])
2175
- offsets = np .column_stack ([xs , ys ])
2171
+ xs = self .convert_xunits (offsets [:, 0 ])
2172
+ ys = self .convert_yunits (offsets [:, 1 ])
2173
+ offsets = np .column_stack ([xs , ys ])
2176
2174
2177
2175
self .update_scalarmappable ()
2178
2176
0 commit comments