@@ -146,6 +146,8 @@ def __init__(self,
146
146
self ._joinstyle = None
147
147
148
148
self ._offsets = np .zeros ((1 , 2 ))
149
+ # save if offsets passed in were none...
150
+ self ._offsetsNone = offsets is None
149
151
self ._uniform_offsets = None
150
152
if offsets is not None :
151
153
offsets = np .asanyarray (offsets , float )
@@ -179,9 +181,30 @@ def get_offset_transform(self):
179
181
return t
180
182
181
183
def get_datalim (self , transData ):
184
+
185
+ # Get the automatic datalim of the collection.
186
+ #
187
+ # This operation depends on the transforms for the data in the
188
+ # collection and whether the collection has offsets.
189
+ #
190
+ # 1) offsets = None, transform child of transData: use the paths for
191
+ # the automatic limits (i.e. for LineCollection in streamline).
192
+ # 2) offsets != None: offset_transform is child of transData:
193
+ # a) transform is child of transData: use the path + offset for
194
+ # limits (i.e for bar).
195
+ # b) transform is not a child of transData: just use the offsets
196
+ # for the limits (i.e. for scatter)
197
+ # 3) otherwise return a null Bbox.
198
+
182
199
transform = self .get_transform ()
183
200
transOffset = self .get_offset_transform ()
201
+ if (not self ._offsetsNone and
202
+ not transOffset .contains_branch (transData )):
203
+ # if there are offsets but in some co-ords other than data,
204
+ # then don't use them for autoscaling.
205
+ return transforms .Bbox .null ()
184
206
offsets = self ._offsets
207
+
185
208
paths = self .get_paths ()
186
209
187
210
if not transform .is_affine :
@@ -195,13 +218,32 @@ def get_datalim(self, transData):
195
218
offsets = offsets .filled (np .nan )
196
219
# get_path_collection_extents handles nan but not masked arrays
197
220
221
+ result = transforms .Bbox .null ()
198
222
if len (paths ) and len (offsets ):
199
- result = mpath .get_path_collection_extents (
200
- transform .frozen (), paths , self .get_transforms (),
201
- offsets , transOffset .frozen ())
202
- result = result .inverse_transformed (transData )
203
- else :
204
- result = transforms .Bbox .null ()
223
+ if (not self ._offsetsNone and
224
+ not transform .contains_branch (transData )):
225
+ # this is for collections that have their paths (shapes)
226
+ # in physical, axes-relative, or figure-relative units
227
+ # (i.e. like scatter). We can't uniquely set limits based on
228
+ # those shapes, so we just set the limits based on their
229
+ # location.
230
+ # Finish the transform:
231
+ offsets = transOffset .transform (offsets )
232
+ offsets = transData .inverted ().transform (offsets )
233
+ offsets = np .ma .masked_invalid (offsets )
234
+ extents = [[np .min (offsets [:, 0 ]), np .min (offsets [:, 1 ])],
235
+ [np .max (offsets [:, 0 ]), np .max (offsets [:, 1 ])]]
236
+ result = transforms .Bbox (extents )
237
+ elif transform .contains_branch (transData ):
238
+ # collections that are just in data units (like quiver)
239
+ # can properly have the axes limits set by their shape +
240
+ # offset. LineCollections that have no offsets can
241
+ # also use this algorithm (like streamplot).
242
+ result = mpath .get_path_collection_extents (
243
+ transform .frozen (), paths , self .get_transforms (),
244
+ offsets , transOffset .frozen ())
245
+ result = result .inverse_transformed (transData )
246
+
205
247
return result
206
248
207
249
def get_window_extent (self , renderer ):
@@ -1314,7 +1356,6 @@ def __init__(self, segments, # Can be None.
1314
1356
antialiaseds = (mpl .rcParams ['lines.antialiased' ],)
1315
1357
1316
1358
colors = mcolors .to_rgba_array (colors )
1317
-
1318
1359
Collection .__init__ (
1319
1360
self ,
1320
1361
edgecolors = colors ,
0 commit comments