@@ -62,7 +62,6 @@ class Collection(artist.Artist, cm.ScalarMappable):
62
62
mappable will be used to set the ``facecolors`` and ``edgecolors``,
63
63
ignoring those that were manually passed in.
64
64
"""
65
- _offsets = np .zeros ((0 , 2 ))
66
65
#: Either a list of 3x3 arrays or an Nx3x3 array (representing N
67
66
#: transforms), suitable for the `all_transforms` argument to
68
67
#: `~matplotlib.backend_bases.RendererBase.draw_path_collection`;
@@ -193,16 +192,12 @@ 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
- self ._has_offsets = offsets is not None
199
-
200
- if self ._has_offsets :
195
+ if offsets is not None :
201
196
offsets = np .asanyarray (offsets , float )
202
197
# Broadcast (2,) -> (1, 2) but nothing else.
203
198
if offsets .shape == (2 ,):
204
199
offsets = offsets [None , :]
205
- self ._offsets = offsets
200
+ self ._offsets = offsets
206
201
207
202
self ._offset_transform = offset_transform
208
203
@@ -264,9 +259,12 @@ def get_datalim(self, transData):
264
259
# if the offsets are in some coords other than data,
265
260
# then don't use them for autoscaling.
266
261
return transforms .Bbox .null ()
267
- offsets = self ._offsets
262
+ offsets = self .get_offsets ()
268
263
269
264
paths = self .get_paths ()
265
+ if not len (paths ):
266
+ # No paths to transform
267
+ return transforms .Bbox .null ()
270
268
271
269
if not transform .is_affine :
272
270
paths = [transform .transform_path_non_affine (p ) for p in paths ]
@@ -275,35 +273,34 @@ def get_datalim(self, transData):
275
273
# transforms.get_affine().contains_branch(transData). But later,
276
274
# be careful to only apply the affine part that remains.
277
275
278
- if isinstance (offsets , np .ma .MaskedArray ):
279
- offsets = offsets .filled (np .nan )
280
- # get_path_collection_extents handles nan but not masked arrays
281
-
282
- if len (paths ):
283
- if any (transform .contains_branch_seperately (transData )):
284
- # collections that are just in data units (like quiver)
285
- # can properly have the axes limits set by their shape +
286
- # offset. LineCollections that have no offsets can
287
- # also use this algorithm (like streamplot).
288
- return mpath .get_path_collection_extents (
289
- transform .get_affine () - transData , paths ,
290
- self .get_transforms (),
291
- offset_trf .transform_non_affine (offsets ),
292
- offset_trf .get_affine ().frozen ())
293
-
294
- if self ._has_offsets :
295
- # this is for collections that have their paths (shapes)
296
- # in physical, axes-relative, or figure-relative units
297
- # (i.e. like scatter). We can't uniquely set limits based on
298
- # those shapes, so we just set the limits based on their
299
- # location.
300
- offsets = (offset_trf - transData ).transform (offsets )
301
- # note A-B means A B^{-1}
302
- offsets = np .ma .masked_invalid (offsets )
303
- if not offsets .mask .all ():
304
- bbox = transforms .Bbox .null ()
305
- bbox .update_from_data_xy (offsets )
306
- return bbox
276
+ if any (transform .contains_branch_seperately (transData )):
277
+ # collections that are just in data units (like quiver)
278
+ # can properly have the axes limits set by their shape +
279
+ # offset. LineCollections that have no offsets can
280
+ # also use this algorithm (like streamplot).
281
+ if isinstance (offsets , np .ma .MaskedArray ):
282
+ offsets = offsets .filled (np .nan )
283
+ # get_path_collection_extents handles nan but not masked arrays
284
+ return mpath .get_path_collection_extents (
285
+ transform .get_affine () - transData , paths ,
286
+ self .get_transforms (),
287
+ offset_trf .transform_non_affine (offsets ),
288
+ offset_trf .get_affine ().frozen ())
289
+
290
+ # NOTE: None is the default case where no offsets were passed in
291
+ if self ._offsets is not None :
292
+ # this is for collections that have their paths (shapes)
293
+ # in physical, axes-relative, or figure-relative units
294
+ # (i.e. like scatter). We can't uniquely set limits based on
295
+ # those shapes, so we just set the limits based on their
296
+ # location.
297
+ offsets = (offset_trf - transData ).transform (offsets )
298
+ # note A-B means A B^{-1}
299
+ offsets = np .ma .masked_invalid (offsets )
300
+ if not offsets .mask .all ():
301
+ bbox = transforms .Bbox .null ()
302
+ bbox .update_from_data_xy (offsets )
303
+ return bbox
307
304
return transforms .Bbox .null ()
308
305
309
306
def get_window_extent (self , renderer ):
@@ -316,7 +313,7 @@ def _prepare_points(self):
316
313
317
314
transform = self .get_transform ()
318
315
offset_trf = self .get_offset_transform ()
319
- offsets = self ._offsets
316
+ offsets = self .get_offsets ()
320
317
paths = self .get_paths ()
321
318
322
319
if self .have_units ():
@@ -327,10 +324,9 @@ def _prepare_points(self):
327
324
xs = self .convert_xunits (xs )
328
325
ys = self .convert_yunits (ys )
329
326
paths .append (mpath .Path (np .column_stack ([xs , ys ]), path .codes ))
330
- if offsets .size :
331
- xs = self .convert_xunits (offsets [:, 0 ])
332
- ys = self .convert_yunits (offsets [:, 1 ])
333
- offsets = np .column_stack ([xs , ys ])
327
+ xs = self .convert_xunits (offsets [:, 0 ])
328
+ ys = self .convert_yunits (offsets [:, 1 ])
329
+ offsets = np .column_stack ([xs , ys ])
334
330
335
331
if not transform .is_affine :
336
332
paths = [transform .transform_path_non_affine (path )
@@ -559,7 +555,8 @@ def set_offsets(self, offsets):
559
555
560
556
def get_offsets (self ):
561
557
"""Return the offsets for the collection."""
562
- return self ._offsets
558
+ # Default to zeros in the no-offset (None) case
559
+ return np .zeros ((1 , 2 )) if self ._offsets is None else self ._offsets
563
560
564
561
def _get_default_linewidth (self ):
565
562
# This may be overridden in a subclass.
@@ -2156,13 +2153,12 @@ def draw(self, renderer):
2156
2153
renderer .open_group (self .__class__ .__name__ , self .get_gid ())
2157
2154
transform = self .get_transform ()
2158
2155
offset_trf = self .get_offset_transform ()
2159
- offsets = self ._offsets
2156
+ offsets = self .get_offsets ()
2160
2157
2161
2158
if self .have_units ():
2162
- if len (self ._offsets ):
2163
- xs = self .convert_xunits (self ._offsets [:, 0 ])
2164
- ys = self .convert_yunits (self ._offsets [:, 1 ])
2165
- offsets = np .column_stack ([xs , ys ])
2159
+ xs = self .convert_xunits (offsets [:, 0 ])
2160
+ ys = self .convert_yunits (offsets [:, 1 ])
2161
+ offsets = np .column_stack ([xs , ys ])
2166
2162
2167
2163
self .update_scalarmappable ()
2168
2164
0 commit comments