Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b6fd848

Browse files
committed
Clarify how get_path_collection_extents works. Add get_paths_extents as a convenience wrapper around it.
1 parent 76665d0 commit b6fd848

File tree

1 file changed

+45
-5
lines changed

1 file changed

+45
-5
lines changed

lib/matplotlib/path.py

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -710,12 +710,52 @@ def hatch(cls, hatchpattern, density=6):
710710
return hatch_path
711711

712712
_get_path_collection_extents = get_path_collection_extents
713-
def get_path_collection_extents(*args):
713+
def get_path_collection_extents(
714+
master_transform, paths, transforms, offsets, offset_transform):
714715
"""
715-
Given a sequence of :class:`Path` objects, returns the bounding
716-
box that encapsulates all of them.
716+
Given a sequence of :class:`Path` objects, :class:`Transform`
717+
objects and offsets, as found in a
718+
:class:`collections.PathCollection`, returns the bounding box that
719+
encapsulates all of them.
720+
721+
*master_transform* is a global transformation to apply to all paths
722+
723+
*paths* is a sequence of :class:`Path` instances.
724+
725+
*transforms* is a sequence of :class:`Affine2D` instances.
726+
727+
*offsets* is a sequence of (x, y) offsets (or an Nx2 array)
728+
729+
*offset_transform* is a :class:`Affine2D` to apply to the offsets
730+
before applying the offset to the path.
731+
732+
The way that *paths*, *transforms* and *offsets* are combined
733+
follows the same method as for collections. Each is iterated over
734+
independently, so if you have 3 paths, 2 transforms and 1 offset,
735+
their combinations are as follows:
736+
737+
(A, A, A), (B, B, A), (C, A, A)
717738
"""
718739
from transforms import Bbox
719-
if len(args[1]) == 0:
740+
if len(paths) == 0:
720741
raise ValueError("No paths provided")
721-
return Bbox.from_extents(*_get_path_collection_extents(*args))
742+
return Bbox.from_extents(*_get_path_collection_extents(
743+
master_transform, paths, transforms, offsets, offset_transform))
744+
745+
def get_paths_extents(paths, transforms=[]):
746+
"""
747+
Given a sequence of :class:`Path` objects and optional
748+
:class:`Transform` objects, returns the bounding box that
749+
encapsulates all of them.
750+
751+
*paths* is a sequence of :class:`Path` instances.
752+
753+
*transforms* is an optional sequence of :class:`Affine2D`
754+
instances to apply to each path.
755+
"""
756+
from transforms import Bbox, Affine2D
757+
if len(paths) == 0:
758+
raise ValueError("No paths provided")
759+
return Bbox.from_extents(*_get_path_collection_extents(
760+
Affine2D(), paths, transforms, [], Affine2D()))
761+

0 commit comments

Comments
 (0)