MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / get_datalim

Method get_datalim

lib/matplotlib/collections.py:247–317  ·  view source on GitHub ↗
(self, transData)

Source from the content-addressed store, hash-verified

245 self._offset_transform = offset_transform
246
247 def get_datalim(self, transData):
248 # Calculate the data limits and return them as a `.Bbox`.
249 #
250 # This operation depends on the transforms for the data in the
251 # collection and whether the collection has offsets:
252 #
253 # 1. offsets = None, transform child of transData: use the paths for
254 # the automatic limits (i.e. for LineCollection in streamline).
255 # 2. offsets != None: offset_transform is child of transData:
256 #
257 # a. transform is child of transData: use the path + offset for
258 # limits (i.e for bar).
259 # b. transform is not a child of transData: just use the offsets
260 # for the limits (i.e. for scatter)
261 #
262 # 3. otherwise return a null Bbox.
263
264 transform = self.get_transform()
265 offset_trf = self.get_offset_transform()
266 if not (isinstance(offset_trf, transforms.IdentityTransform)
267 or offset_trf.contains_branch(transData)):
268 # if the offsets are in some coords other than data,
269 # then don't use them for autoscaling.
270 return transforms.Bbox.null()
271
272 paths = self.get_paths()
273 if not len(paths):
274 # No paths to transform
275 return transforms.Bbox.null()
276
277 if not transform.is_affine:
278 paths = [transform.transform_path_non_affine(p) for p in paths]
279 # Don't convert transform to transform.get_affine() here because
280 # we may have transform.contains_branch(transData) but not
281 # transforms.get_affine().contains_branch(transData). But later,
282 # be careful to only apply the affine part that remains.
283
284 offsets = self.get_offsets()
285
286 if any(transform.contains_branch_separately(transData)):
287 # collections that are just in data units (like quiver)
288 # can properly have the axes limits set by their shape +
289 # offset. LineCollections that have no offsets can
290 # also use this algorithm (like streamplot).
291 if isinstance(offsets, np.ma.MaskedArray):
292 offsets = offsets.filled(np.nan)
293 # get_path_collection_extents handles nan but not masked arrays
294 data_trf = transform.get_affine() - transData
295 if not data_trf.is_affine:
296 paths = [data_trf.transform_path_non_affine(p) for p in paths]
297 return mpath.get_path_collection_extents(
298 data_trf.get_affine(), paths,
299 self.get_transforms(),
300 offset_trf.transform_non_affine(offsets),
301 offset_trf.get_affine().frozen())
302
303 # NOTE: None is the default case where no offsets were passed in
304 if self._offsets is not None:

Callers 1

get_window_extentMethod · 0.95

Calls 14

get_offset_transformMethod · 0.95
get_pathsMethod · 0.95
get_offsetsMethod · 0.95
get_transformsMethod · 0.95
nullMethod · 0.80
update_from_data_xyMethod · 0.80
get_transformMethod · 0.45
contains_branchMethod · 0.45
get_affineMethod · 0.45
transform_non_affineMethod · 0.45

Tested by

no test coverage detected