@@ -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,15 +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
-
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
200
+ self ._offsets = offsets
205
201
206
202
self ._offset_transform = offset_transform
207
203
@@ -263,9 +259,12 @@ def get_datalim(self, transData):
263
259
# if the offsets are in some coords other than data,
264
260
# then don't use them for autoscaling.
265
261
return transforms .Bbox .null ()
266
- offsets = self ._offsets
262
+ offsets = self .get_offsets ()
267
263
268
264
paths = self .get_paths ()
265
+ if not len (paths ):
266
+ # No paths to transform
267
+ return transforms .Bbox .null ()
269
268
270
269
if not transform .is_affine :
271
270
paths = [transform .transform_path_non_affine (p ) for p in paths ]
@@ -274,22 +273,22 @@ def get_datalim(self, transData):
274
273
# transforms.get_affine().contains_branch(transData). But later,
275
274
# be careful to only apply the affine part that remains.
276
275
277
- if isinstance ( offsets , np . ma . MaskedArray ):
278
- offsets = offsets . filled ( np . nan )
279
- # get_path_collection_extents handles nan but not masked arrays
280
-
281
- if len ( paths ) and len ( offsets ):
282
- if any ( transform . contains_branch_seperately ( transData ) ):
283
- # collections that are just in data units (like quiver )
284
- # can properly have the axes limits set by their shape +
285
- # offset. LineCollections that have no offsets can
286
- # also use this algorithm (like streamplot).
287
- return mpath . get_path_collection_extents (
288
- transform . get_affine () - transData , paths ,
289
- self . get_transforms (),
290
- offset_trf . transform_non_affine ( offsets ),
291
- offset_trf . get_affine (). frozen ())
292
-
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 :
293
292
# this is for collections that have their paths (shapes)
294
293
# in physical, axes-relative, or figure-relative units
295
294
# (i.e. like scatter). We can't uniquely set limits based on
@@ -314,7 +313,7 @@ def _prepare_points(self):
314
313
315
314
transform = self .get_transform ()
316
315
offset_trf = self .get_offset_transform ()
317
- offsets = self ._offsets
316
+ offsets = self .get_offsets ()
318
317
paths = self .get_paths ()
319
318
320
319
if self .have_units ():
@@ -325,10 +324,9 @@ def _prepare_points(self):
325
324
xs = self .convert_xunits (xs )
326
325
ys = self .convert_yunits (ys )
327
326
paths .append (mpath .Path (np .column_stack ([xs , ys ]), path .codes ))
328
- if offsets .size :
329
- xs = self .convert_xunits (offsets [:, 0 ])
330
- ys = self .convert_yunits (offsets [:, 1 ])
331
- 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 ])
332
330
333
331
if not transform .is_affine :
334
332
paths = [transform .transform_path_non_affine (path )
@@ -557,7 +555,8 @@ def set_offsets(self, offsets):
557
555
558
556
def get_offsets (self ):
559
557
"""Return the offsets for the collection."""
560
- 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
561
560
562
561
def _get_default_linewidth (self ):
563
562
# This may be overridden in a subclass.
@@ -2154,13 +2153,12 @@ def draw(self, renderer):
2154
2153
renderer .open_group (self .__class__ .__name__ , self .get_gid ())
2155
2154
transform = self .get_transform ()
2156
2155
offset_trf = self .get_offset_transform ()
2157
- offsets = self ._offsets
2156
+ offsets = self .get_offsets ()
2158
2157
2159
2158
if self .have_units ():
2160
- if len (self ._offsets ):
2161
- xs = self .convert_xunits (self ._offsets [:, 0 ])
2162
- ys = self .convert_yunits (self ._offsets [:, 1 ])
2163
- 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 ])
2164
2162
2165
2163
self .update_scalarmappable ()
2166
2164
0 commit comments