matplotlib.transforms#

Inheritance diagram of matplotlib.transforms

Matplotlib includes a framework for arbitrary geometric transformations that is used todetermine the final position of all elements drawn on the canvas.

Transforms are composed into trees ofTransformNode objectswhose actual value depends on their children. When the contents ofchildren change, their parents are automatically invalidated. Thenext time an invalidated transform is accessed, it is recomputed toreflect those changes. This invalidation/caching approach preventsunnecessary recomputations of transforms, and contributes to betterinteractive performance.

For example, here is a graph of the transform tree used to plot data to the figure:

Diagram of transform tree from data to figure coordinates.

The framework can be used for both affine and non-affinetransformations. However, for speed, we want to use the backendrenderers to perform affine transformations whenever possible.Therefore, it is possible to perform just the affine or non-affinepart of a transformation on a set of data. The affine is alwaysassumed to occur after the non-affine. For any transform:

fulltransform==non-affinepart+affinepart

The backends are not expected to handle non-affine transformationsthemselves.

See the tutorialTransformations Tutorial for examplesof how to use transforms.

classmatplotlib.transforms.Affine2D(matrix=None,**kwargs)[source]#

Bases:Affine2DBase

A mutable 2D affine transformation.

Initialize an Affine transform from a 3x3 numpy float array:

acebdf001

Ifmatrix is None, initialize with the identity transform.

clear()[source]#

Reset the underlying matrix to the identity transform.

staticfrom_values(a,b,c,d,e,f)[source]#

Create a new Affine2D instance from the given values:

acebdf001

.

get_matrix()[source]#

Get the underlying transformation matrix as a 3x3 array:

acebdf001

.

rotate(theta)[source]#

Add a rotation (in radians) to this transform in place.

Returnsself, so this method can easily be chained with morecalls torotate(),rotate_deg(),translate()andscale().

rotate_around(x,y,theta)[source]#

Add a rotation (in radians) around the point (x, y) in place.

Returnsself, so this method can easily be chained with morecalls torotate(),rotate_deg(),translate()andscale().

rotate_deg(degrees)[source]#

Add a rotation (in degrees) to this transform in place.

Returnsself, so this method can easily be chained with morecalls torotate(),rotate_deg(),translate()andscale().

rotate_deg_around(x,y,degrees)[source]#

Add a rotation (in degrees) around the point (x, y) in place.

Returnsself, so this method can easily be chained with morecalls torotate(),rotate_deg(),translate()andscale().

scale(sx,sy=None)[source]#

Add a scale in place.

Ifsy is None, the same scale is applied in both thex- andy-directions.

Returnsself, so this method can easily be chained with morecalls torotate(),rotate_deg(),translate()andscale().

set(other)[source]#

Set this transformation from the frozen copy of anotherAffine2DBase object.

set_matrix(mtx)[source]#

Set the underlying transformation matrix from a 3x3 array:

acebdf001

.

skew(xShear,yShear)[source]#

Add a skew in place.

xShear andyShear are the shear angles along thex- andy-axes, respectively, in radians.

Returnsself, so this method can easily be chained with morecalls torotate(),rotate_deg(),translate()andscale().

skew_deg(xShear,yShear)[source]#

Add a skew in place.

xShear andyShear are the shear angles along thex- andy-axes, respectively, in degrees.

Returnsself, so this method can easily be chained with morecalls torotate(),rotate_deg(),translate()andscale().

translate(tx,ty)[source]#

Add a translation in place.

Returnsself, so this method can easily be chained with morecalls torotate(),rotate_deg(),translate()andscale().

classmatplotlib.transforms.Affine2DBase(*args,**kwargs)[source]#

Bases:AffineBase

The base class of all 2D affine transformations.

2D affine transformations are performed using a 3x3 numpy array:

acebdf001

This class provides the read-only interface. For a mutable 2Daffine transformation, useAffine2D.

Subclasses of this class will generally only need to override aconstructor andget_matrix that generates a custom 3x3 matrix.

Parameters:
shorthand_namestr

A string representing the "name" of the transform. The name carriesno significance other than to improve the readability ofstr(transform) when DEBUG=True.

frozen()[source]#

Return a frozen copy of this transform node. The frozen copy will notbe updated when its children change. Useful for storing a previouslyknown state of a transform wherecopy.deepcopy() might normally beused.

has_inverse=True#

True if this transform has a corresponding inverse transform.

input_dims=2#

The number of input dimensions of this transform.Must be overridden (with integers) in the subclass.

inverted()[source]#

Return the corresponding inverse transformation.

It holdsx==self.inverted().transform(self.transform(x)).

The return value of this method should be treated astemporary. An update toself does not cause a correspondingupdate to its inverted copy.

propertyis_separable#

Returns True when the argument is true, False otherwise.The builtins True and False are the only two instances of the class bool.The class bool is a subclass of the class int, and cannot be subclassed.

output_dims=2#

The number of output dimensions of this transform.Must be overridden (with integers) in the subclass.

to_values()[source]#

Return the values of the matrix as an(a,b,c,d,e,f) tuple.

transform_affine(values)[source]#

Apply only the affine part of this transformation on thegiven array of values.

transform(values) is always equivalent totransform_affine(transform_non_affine(values)).

In non-affine transformations, this is generally a no-op. Inaffine transformations, this is equivalent totransform(values).

Parameters:
valuesarray

The input values as an array of lengthinput_dims orshape (N,input_dims).

Returns:
array

The output values as an array of lengthoutput_dims orshape (N,output_dims), depending on the input.

classmatplotlib.transforms.AffineBase(*args,**kwargs)[source]#

Bases:Transform

The base class of all affine transformations of any number of dimensions.

Parameters:
shorthand_namestr

A string representing the "name" of the transform. The name carriesno significance other than to improve the readability ofstr(transform) when DEBUG=True.

get_affine()[source]#

Get the affine part of this transform.

is_affine=True#
transform(values)[source]#

Apply this transformation on the given array ofvalues.

Parameters:
valuesarray-like

The input values as an array of lengthinput_dims orshape (N,input_dims).

Returns:
array

The output values as an array of lengthoutput_dims orshape (N,output_dims), depending on the input.

transform_affine(values)[source]#

Apply only the affine part of this transformation on thegiven array of values.

transform(values) is always equivalent totransform_affine(transform_non_affine(values)).

In non-affine transformations, this is generally a no-op. Inaffine transformations, this is equivalent totransform(values).

Parameters:
valuesarray

The input values as an array of lengthinput_dims orshape (N,input_dims).

Returns:
array

The output values as an array of lengthoutput_dims orshape (N,output_dims), depending on the input.

transform_non_affine(values)[source]#

Apply only the non-affine part of this transformation.

transform(values) is always equivalent totransform_affine(transform_non_affine(values)).

In non-affine transformations, this is generally equivalent totransform(values). In affine transformations, this isalways a no-op.

Parameters:
valuesarray

The input values as an array of lengthinput_dims orshape (N,input_dims).

Returns:
array

The output values as an array of lengthoutput_dims orshape (N,output_dims), depending on the input.

transform_path(path)[source]#

Apply the transform toPathpath, returning a newPath.

In some cases, this transform may insert curves into the paththat began as line segments.

transform_path_affine(path)[source]#

Apply the affine part of this transform toPathpath, returning anewPath.

transform_path(path) is equivalent totransform_path_affine(transform_path_non_affine(values)).

transform_path_non_affine(path)[source]#

Apply the non-affine part of this transform toPathpath,returning a newPath.

transform_path(path) is equivalent totransform_path_affine(transform_path_non_affine(values)).

classmatplotlib.transforms.AffineDeltaTransform(transform,**kwargs)[source]#

Bases:Affine2DBase

A transform wrapper for transforming displacements between pairs of points.

This class is intended to be used to transform displacements ("positiondeltas") between pairs of points (e.g., as theoffset_transformofCollections): given a transformt such thatt=AffineDeltaTransform(t)+offset,AffineDeltaTransformsatisfiesAffineDeltaTransform(a-b)==AffineDeltaTransform(a)-AffineDeltaTransform(b).

This is implemented by forcing the offset components of the transformmatrix to zero.

This class is experimental as of 3.3, and the API may change.

Parameters:
shorthand_namestr

A string representing the "name" of the transform. The name carriesno significance other than to improve the readability ofstr(transform) when DEBUG=True.

get_matrix()[source]#

Get the matrix for the affine part of this transform.

pass_through=True#

If pass_through is True, all ancestors will always beinvalidated, even if 'self' is already invalid.

classmatplotlib.transforms.Bbox(points,**kwargs)[source]#

Bases:BboxBase

A mutable bounding box.

Examples

Create from known bounds

The default constructor takes the boundary "points"[[xmin,ymin],[xmax,ymax]].

>>>Bbox([[1,1],[3,7]])Bbox([[1.0, 1.0], [3.0, 7.0]])

Alternatively, a Bbox can be created from the flattened points array, theso-called "extents"(xmin,ymin,xmax,ymax)

>>>Bbox.from_extents(1,1,3,7)Bbox([[1.0, 1.0], [3.0, 7.0]])

or from the "bounds"(xmin,ymin,width,height).

>>>Bbox.from_bounds(1,1,2,6)Bbox([[1.0, 1.0], [3.0, 7.0]])

Create from collections of points

The "empty" object for accumulating Bboxs is the null bbox, which is astand-in for the empty set.

>>>Bbox.null()Bbox([[inf, inf], [-inf, -inf]])

Adding points to the null bbox will give you the bbox of those points.

>>>box=Bbox.null()>>>box.update_from_data_xy([[1,1]])>>>boxBbox([[1.0, 1.0], [1.0, 1.0]])>>>box.update_from_data_xy([[2,3],[3,2]],ignore=False)>>>boxBbox([[1.0, 1.0], [3.0, 3.0]])

Settingignore=True is equivalent to starting over from a null bbox.

>>>box.update_from_data_xy([[1,1]],ignore=True)>>>boxBbox([[1.0, 1.0], [1.0, 1.0]])

Warning

It is recommended to always specifyignore explicitly. If not, thedefault value ofignore can be changed at any time by code withaccess to your Bbox, for example using the methodignore.

Properties of the ``null`` bbox

Note

The current behavior ofBbox.null() may be surprising as it doesnot have all of the properties of the "empty set", and as such doesnot behave like a "zero" object in the mathematical sense. We maychange that in the future (with a deprecation period).

The null bbox is the identity for intersections

>>>Bbox.intersection(Bbox([[1,1],[3,7]]),Bbox.null())Bbox([[1.0, 1.0], [3.0, 7.0]])

except with itself, where it returns the full space.

>>>Bbox.intersection(Bbox.null(),Bbox.null())Bbox([[-inf, -inf], [inf, inf]])

A union containing null will always return the full space (not the otherset!)

>>>Bbox.union([Bbox([[0,0],[0,0]]),Bbox.null()])Bbox([[-inf, -inf], [inf, inf]])
Parameters:
pointsndarray

A (2, 2) array of the form[[x0,y0],[x1,y1]].

propertybounds#

Return (x0,y0,width,height).

staticfrom_bounds(x0,y0,width,height)[source]#

Create a newBbox fromx0,y0,width andheight.

width andheight may be negative.

staticfrom_extents(*args,minpos=None)[source]#

Create a new Bbox fromleft,bottom,right andtop.

They-axis increases upwards.

Parameters:
left, bottom, right, topfloat

The four extents of the bounding box.

minposfloat or None

If this is supplied, the Bbox will have a minimum positive valueset. This is useful when dealing with logarithmic scales and otherscales where negative bounds result in floating point errors.

frozen()[source]#

The base class for anything that participates in the transform treeand needs to invalidate its parents or be invalidated. This includesclasses that are not really transforms, such as bounding boxes, since sometransforms depend on bounding boxes to compute their values.

get_points()[source]#

Get the points of the bounding box as an array of the form[[x0,y0],[x1,y1]].

ignore(value)[source]#

Set whether the existing bounds of the box should be ignoredby subsequent calls toupdate_from_data_xy().

valuebool
propertyintervalx#

The pair ofx coordinates that define the bounding box.

This is not guaranteed to be sorted from left to right.

propertyintervaly#

The pair ofy coordinates that define the bounding box.

This is not guaranteed to be sorted from bottom to top.

propertyminpos#

The minimum positive value in both directions within the Bbox.

This is useful when dealing with logarithmic scales and other scaleswhere negative bounds result in floating point errors, and will be usedas the minimum extent instead ofp0.

propertyminposx#

The minimum positive value in thex-direction within the Bbox.

This is useful when dealing with logarithmic scales and other scaleswhere negative bounds result in floating point errors, and will be usedas the minimumx-extent instead ofx0.

propertyminposy#

The minimum positive value in they-direction within the Bbox.

This is useful when dealing with logarithmic scales and other scaleswhere negative bounds result in floating point errors, and will be usedas the minimumy-extent instead ofy0.

mutated()[source]#

Return whether the bbox has changed since init.

mutatedx()[source]#

Return whether the x-limits have changed since init.

mutatedy()[source]#

Return whether the y-limits have changed since init.

staticnull()[source]#

Create a new nullBbox from (inf, inf) to (-inf, -inf).

propertyp0#

The first pair of (x,y) coordinates that define the bounding box.

This is not guaranteed to be the bottom-left corner (for that, usemin).

propertyp1#

The second pair of (x,y) coordinates that define the bounding box.

This is not guaranteed to be the top-right corner (for that, usemax).

set(other)[source]#

Set this bounding box from the "frozen" bounds of anotherBbox.

set_points(points)[source]#

Set the points of the bounding box directly from an array of the form[[x0,y0],[x1,y1]]. No error checking is performed, as thismethod is mainly for internal use.

staticunit()[source]#

Create a new unitBbox from (0, 0) to (1, 1).

update_from_data_x(x,ignore=None)[source]#

Update the x-bounds of theBbox based on the passed in data. Afterupdating, the bounds will have positivewidth, andx0 will be theminimal value.

Parameters:
xndarray

Array of x-values.

ignorebool, optional
  • WhenTrue, ignore the existing bounds of theBbox.

  • WhenFalse, include the existing bounds of theBbox.

  • WhenNone, use the last value passed toignore().

update_from_data_xy(xy,ignore=None,updatex=True,updatey=True)[source]#

Update theBbox bounds based on the passed inxy coordinates.

After updating, the bounds will have positivewidth andheight;x0 andy0 will be the minimal values.

Parameters:
xy(N, 2) array-like

The (x, y) coordinates.

ignorebool, optional
  • WhenTrue, ignore the existing bounds of theBbox.

  • WhenFalse, include the existing bounds of theBbox.

  • WhenNone, use the last value passed toignore().

updatex, updateybool, default: True

WhenTrue, update the x/y values.

update_from_data_y(y,ignore=None)[source]#

Update the y-bounds of theBbox based on the passed in data. Afterupdating, the bounds will have positiveheight, andy0 will be theminimal value.

Parameters:
yndarray

Array of y-values.

ignorebool, optional
  • WhenTrue, ignore the existing bounds of theBbox.

  • WhenFalse, include the existing bounds of theBbox.

  • WhenNone, use the last value passed toignore().

update_from_path(path,ignore=None,updatex=True,updatey=True)[source]#

Update the bounds of theBbox to contain the vertices of theprovided path. After updating, the bounds will have positivewidthandheight;x0 andy0 will be the minimal values.

Parameters:
pathPath
ignorebool, optional
  • WhenTrue, ignore the existing bounds of theBbox.

  • WhenFalse, include the existing bounds of theBbox.

  • WhenNone, use the last value passed toignore().

updatex, updateybool, default: True

WhenTrue, update the x/y values.

propertyx0#

The first of the pair ofx coordinates that define the bounding box.

This is not guaranteed to be less thanx1 (for that, usexmin).

propertyx1#

The second of the pair ofx coordinates that define the bounding box.

This is not guaranteed to be greater thanx0 (for that, usexmax).

propertyy0#

The first of the pair ofy coordinates that define the bounding box.

This is not guaranteed to be less thany1 (for that, useymin).

propertyy1#

The second of the pair ofy coordinates that define the bounding box.

This is not guaranteed to be greater thany0 (for that, useymax).

classmatplotlib.transforms.BboxBase(shorthand_name=None)[source]#

Bases:TransformNode

The base class of all bounding boxes.

This class is immutable;Bbox is a mutable subclass.

The canonical representation is as two points, with norestrictions on their ordering. Convenience properties areprovided to get the left, bottom, right and top edges and widthand height, but these are not stored explicitly.

Parameters:
shorthand_namestr

A string representing the "name" of the transform. The name carriesno significance other than to improve the readability ofstr(transform) when DEBUG=True.

anchored(c,container)[source]#

Return a copy of theBbox anchored toc withincontainer.

Parameters:
c(float, float) or {'C', 'SW', 'S', 'SE', 'E', 'NE', ...}

Either an (x,y) pair of relative coordinates (0 is left orbottom, 1 is right or top), 'C' (center), or a cardinal direction('SW', southwest, is bottom left, etc.).

containerBbox

The box within which theBbox is positioned.

propertybounds#

Return (x0,y0,width,height).

coefs={'C':(0.5,0.5),'E':(1.0,0.5),'N':(0.5,1.0),'NE':(1.0,1.0),'NW':(0,1.0),'S':(0.5,0),'SE':(1.0,0),'SW':(0,0),'W':(0,0.5)}#
contains(x,y)[source]#

Return whether(x,y) is in the bounding box or on its edge.

containsx(x)[source]#

Return whetherx is in the closed (x0,x1) interval.

containsy(y)[source]#

Return whethery is in the closed (y0,y1) interval.

corners()[source]#

Return the corners of this rectangle as an array of points.

Specifically, this returns the array[[x0,y0],[x0,y1],[x1,y0],[x1,y1]].

count_contains(vertices)[source]#

Count the number of vertices contained in theBbox.Any vertices with a non-finite x or y value are ignored.

Parameters:
vertices(N, 2) array
count_overlaps(bboxes)[source]#

Count the number of bounding boxes that overlap this one.

Parameters:
bboxessequence ofBboxBase
expanded(sw,sh)[source]#

Construct aBbox by expanding this one around its center by thefactorssw andsh.

propertyextents#

Return (x0,y0,x1,y1).

frozen()[source]#

The base class for anything that participates in the transform treeand needs to invalidate its parents or be invalidated. This includesclasses that are not really transforms, such as bounding boxes, since sometransforms depend on bounding boxes to compute their values.

fully_contains(x,y)[source]#

Return whetherx,y is in the bounding box, but not on its edge.

fully_containsx(x)[source]#

Return whetherx is in the open (x0,x1) interval.

fully_containsy(y)[source]#

Return whethery is in the open (y0,y1) interval.

fully_overlaps(other)[source]#

Return whether this bounding box overlaps with the other bounding box,not including the edges.

Parameters:
otherBboxBase
get_points()[source]#
propertyheight#

The (signed) height of the bounding box.

staticintersection(bbox1,bbox2)[source]#

Return the intersection ofbbox1 andbbox2 if they intersect, orNone if they don't.

propertyintervalx#

The pair ofx coordinates that define the bounding box.

This is not guaranteed to be sorted from left to right.

propertyintervaly#

The pair ofy coordinates that define the bounding box.

This is not guaranteed to be sorted from bottom to top.

is_affine=True#
is_bbox=True#
propertymax#

The top-right corner of the bounding box.

propertymin#

The bottom-left corner of the bounding box.

overlaps(other)[source]#

Return whether this bounding box overlaps with the other bounding box.

Parameters:
otherBboxBase
propertyp0#

The first pair of (x,y) coordinates that define the bounding box.

This is not guaranteed to be the bottom-left corner (for that, usemin).

propertyp1#

The second pair of (x,y) coordinates that define the bounding box.

This is not guaranteed to be the top-right corner (for that, usemax).

padded(w_pad,h_pad=None)[source]#

Construct aBbox by padding this one on all four sides.

Parameters:
w_padfloat

Width pad

h_padfloat, optional

Height pad. Defaults tow_pad.

rotated(radians)[source]#

Return the axes-aligned bounding box that bounds the result of rotatingthisBbox by an angle ofradians.

shrunk(mx,my)[source]#

Return a copy of theBbox, shrunk by the factormxin thex direction and the factormy in they direction.The lower left corner of the box remains unchanged. Normallymx andmy will be less than 1, but this is not enforced.

shrunk_to_aspect(box_aspect,container=None,fig_aspect=1.0)[source]#

Return a copy of theBbox, shrunk so that it is aslarge as it can be while having the desired aspect ratio,box_aspect. If the box coordinates are relative (i.e.fractions of a larger box such as a figure) then thephysical aspect ratio of that figure is specified withfig_aspect, so thatbox_aspect can also be given as aratio of the absolute dimensions, not the relative dimensions.

propertysize#

The (signed) width and height of the bounding box.

splitx(*args)[source]#

Return a list of newBbox objects formed by splitting the originalone with vertical lines at fractional positions given byargs.

splity(*args)[source]#

Return a list of newBbox objects formed by splitting the originalone with horizontal lines at fractional positions given byargs.

transformed(transform)[source]#

Construct aBbox by statically transforming this one bytransform.

translated(tx,ty)[source]#

Construct aBbox by translating this one bytx andty.

staticunion(bboxes)[source]#

Return aBbox that contains all of the givenbboxes.

propertywidth#

The (signed) width of the bounding box.

propertyx0#

The first of the pair ofx coordinates that define the bounding box.

This is not guaranteed to be less thanx1 (for that, usexmin).

propertyx1#

The second of the pair ofx coordinates that define the bounding box.

This is not guaranteed to be greater thanx0 (for that, usexmax).

propertyxmax#

The right edge of the bounding box.

propertyxmin#

The left edge of the bounding box.

propertyy0#

The first of the pair ofy coordinates that define the bounding box.

This is not guaranteed to be less thany1 (for that, useymin).

propertyy1#

The second of the pair ofy coordinates that define the bounding box.

This is not guaranteed to be greater thany0 (for that, useymax).

propertyymax#

The top edge of the bounding box.

propertyymin#

The bottom edge of the bounding box.

classmatplotlib.transforms.BboxTransform(boxin,boxout,**kwargs)[source]#

Bases:Affine2DBase

BboxTransform linearly transforms points from oneBbox to another.

Create a newBboxTransform that linearly transformspoints fromboxin toboxout.

get_matrix()[source]#

Get the matrix for the affine part of this transform.

is_separable=True#

True if this transform is separable in the x- and y- dimensions.

classmatplotlib.transforms.BboxTransformFrom(boxin,**kwargs)[source]#

Bases:Affine2DBase

BboxTransformFrom linearly transforms points from a givenBbox to theunit bounding box.

Parameters:
shorthand_namestr

A string representing the "name" of the transform. The name carriesno significance other than to improve the readability ofstr(transform) when DEBUG=True.

get_matrix()[source]#

Get the matrix for the affine part of this transform.

is_separable=True#

True if this transform is separable in the x- and y- dimensions.

classmatplotlib.transforms.BboxTransformTo(boxout,**kwargs)[source]#

Bases:Affine2DBase

BboxTransformTo is a transformation that linearly transforms points fromthe unit bounding box to a givenBbox.

Create a newBboxTransformTo that linearly transformspoints from the unit bounding box toboxout.

get_matrix()[source]#

Get the matrix for the affine part of this transform.

is_separable=True#

True if this transform is separable in the x- and y- dimensions.

classmatplotlib.transforms.BboxTransformToMaxOnly(boxout,**kwargs)[source]#

Bases:BboxTransformTo

[Deprecated]BboxTransformToMaxOnly is a transformation that linearly transforms points fromthe unit bounding box to a givenBbox with a fixed upper left of (0, 0).

Notes

Deprecated since version 3.9.

Create a newBboxTransformTo that linearly transformspoints from the unit bounding box toboxout.

get_matrix()[source]#

Get the matrix for the affine part of this transform.

classmatplotlib.transforms.BlendedAffine2D(x_transform,y_transform,**kwargs)[source]#

Bases:_BlendedMixin,Affine2DBase

A "blended" transform uses one transform for thex-direction, andanother transform for they-direction.

This version is an optimization for the case where both childtransforms are of typeAffine2DBase.

Create a new "blended" transform usingx_transform to transform thex-axis andy_transform to transform they-axis.

Bothx_transform andy_transform must be 2D affine transforms.

You will generally not call this constructor directly but use theblended_transform_factory function instead, which can determineautomatically which kind of blended transform to create.

get_matrix()[source]#

Get the matrix for the affine part of this transform.

is_separable=True#

True if this transform is separable in the x- and y- dimensions.

classmatplotlib.transforms.BlendedGenericTransform(x_transform,y_transform,**kwargs)[source]#

Bases:_BlendedMixin,Transform

A "blended" transform uses one transform for thex-direction, andanother transform for they-direction.

This "generic" version can handle any given child transform in thex- andy-directions.

Create a new "blended" transform usingx_transform to transform thex-axis andy_transform to transform they-axis.

You will generally not call this constructor directly but use theblended_transform_factory function instead, which can determineautomatically which kind of blended transform to create.

contains_branch(other)[source]#

Return whether the given transform is a sub-tree of this transform.

This routine uses transform equality to identify sub-trees, thereforein many situations it is object id which will be used.

For the case where the given transform represents the wholeof this transform, returns True.

propertydepth#

Return the number of transforms which have been chainedtogether to form this Transform instance.

Note

For the special case of a Composite transform, the maximum depthof the two is returned.

frozen()[source]#

Return a frozen copy of this transform node. The frozen copy will notbe updated when its children change. Useful for storing a previouslyknown state of a transform wherecopy.deepcopy() might normally beused.

get_affine()[source]#

Get the affine part of this transform.

propertyhas_inverse#

Returns True when the argument is true, False otherwise.The builtins True and False are the only two instances of the class bool.The class bool is a subclass of the class int, and cannot be subclassed.

input_dims=2#

The number of input dimensions of this transform.Must be overridden (with integers) in the subclass.

inverted()[source]#

Return the corresponding inverse transformation.

It holdsx==self.inverted().transform(self.transform(x)).

The return value of this method should be treated astemporary. An update toself does not cause a correspondingupdate to its inverted copy.

propertyis_affine#

Returns True when the argument is true, False otherwise.The builtins True and False are the only two instances of the class bool.The class bool is a subclass of the class int, and cannot be subclassed.

is_separable=True#

True if this transform is separable in the x- and y- dimensions.

output_dims=2#

The number of output dimensions of this transform.Must be overridden (with integers) in the subclass.

pass_through=True#

If pass_through is True, all ancestors will always beinvalidated, even if 'self' is already invalid.

transform_non_affine(values)[source]#

Apply only the non-affine part of this transformation.

transform(values) is always equivalent totransform_affine(transform_non_affine(values)).

In non-affine transformations, this is generally equivalent totransform(values). In affine transformations, this isalways a no-op.

Parameters:
valuesarray

The input values as an array of lengthinput_dims orshape (N,input_dims).

Returns:
array

The output values as an array of lengthoutput_dims orshape (N,output_dims), depending on the input.

classmatplotlib.transforms.CompositeAffine2D(a,b,**kwargs)[source]#

Bases:Affine2DBase

A composite transform formed by applying transforma then transformb.

This version is an optimization that handles the case where bothaandb are 2D affines.

Create a new composite transform that is the result ofapplyingAffine2DBasea thenAffine2DBaseb.

You will generally not call this constructor directly but writea+b instead, which will automatically choose the best kind of compositetransform instance to create.

propertydepth#

Return the number of transforms which have been chainedtogether to form this Transform instance.

Note

For the special case of a Composite transform, the maximum depthof the two is returned.

get_matrix()[source]#

Get the matrix for the affine part of this transform.

classmatplotlib.transforms.CompositeGenericTransform(a,b,**kwargs)[source]#

Bases:Transform

A composite transform formed by applying transforma thentransformb.

This "generic" version can handle any two arbitrarytransformations.

Create a new composite transform that is the result ofapplying transforma then transformb.

You will generally not call this constructor directly but writea+b instead, which will automatically choose the best kind of compositetransform instance to create.

contains_branch_seperately(other_transform)[source]#

Return whether the given branch is a sub-tree of this transform oneach separate dimension.

A common use for this method is to identify if a transform is a blendedtransform containing an Axes' data transform. e.g.:

x_isdata,y_isdata=trans.contains_branch_seperately(ax.transData)
propertydepth#

Return the number of transforms which have been chainedtogether to form this Transform instance.

Note

For the special case of a Composite transform, the maximum depthof the two is returned.

frozen()[source]#

Return a frozen copy of this transform node. The frozen copy will notbe updated when its children change. Useful for storing a previouslyknown state of a transform wherecopy.deepcopy() might normally beused.

get_affine()[source]#

Get the affine part of this transform.

propertyhas_inverse#

Returns True when the argument is true, False otherwise.The builtins True and False are the only two instances of the class bool.The class bool is a subclass of the class int, and cannot be subclassed.

inverted()[source]#

Return the corresponding inverse transformation.

It holdsx==self.inverted().transform(self.transform(x)).

The return value of this method should be treated astemporary. An update toself does not cause a correspondingupdate to its inverted copy.

propertyis_affine#

Returns True when the argument is true, False otherwise.The builtins True and False are the only two instances of the class bool.The class bool is a subclass of the class int, and cannot be subclassed.

propertyis_separable#

Returns True when the argument is true, False otherwise.The builtins True and False are the only two instances of the class bool.The class bool is a subclass of the class int, and cannot be subclassed.

pass_through=True#

If pass_through is True, all ancestors will always beinvalidated, even if 'self' is already invalid.

transform_affine(values)[source]#

Apply only the affine part of this transformation on thegiven array of values.

transform(values) is always equivalent totransform_affine(transform_non_affine(values)).

In non-affine transformations, this is generally a no-op. Inaffine transformations, this is equivalent totransform(values).

Parameters:
valuesarray

The input values as an array of lengthinput_dims orshape (N,input_dims).

Returns:
array

The output values as an array of lengthoutput_dims orshape (N,output_dims), depending on the input.

transform_non_affine(values)[source]#

Apply only the non-affine part of this transformation.

transform(values) is always equivalent totransform_affine(transform_non_affine(values)).

In non-affine transformations, this is generally equivalent totransform(values). In affine transformations, this isalways a no-op.

Parameters:
valuesarray

The input values as an array of lengthinput_dims orshape (N,input_dims).

Returns:
array

The output values as an array of lengthoutput_dims orshape (N,output_dims), depending on the input.

transform_path_non_affine(path)[source]#

Apply the non-affine part of this transform toPathpath,returning a newPath.

transform_path(path) is equivalent totransform_path_affine(transform_path_non_affine(values)).

classmatplotlib.transforms.IdentityTransform(*args,**kwargs)[source]#

Bases:Affine2DBase

A special class that does one thing, the identity transform, in afast way.

Parameters:
shorthand_namestr

A string representing the "name" of the transform. The name carriesno significance other than to improve the readability ofstr(transform) when DEBUG=True.

frozen()[source]#

Return a frozen copy of this transform node. The frozen copy will notbe updated when its children change. Useful for storing a previouslyknown state of a transform wherecopy.deepcopy() might normally beused.

get_affine()[source]#

Get the affine part of this transform.

get_matrix()[source]#

Get the matrix for the affine part of this transform.

inverted()[source]#

Return the corresponding inverse transformation.

It holdsx==self.inverted().transform(self.transform(x)).

The return value of this method should be treated astemporary. An update toself does not cause a correspondingupdate to its inverted copy.

transform(values)[source]#

Apply this transformation on the given array ofvalues.

Parameters:
valuesarray-like

The input values as an array of lengthinput_dims orshape (N,input_dims).

Returns:
array

The output values as an array of lengthoutput_dims orshape (N,output_dims), depending on the input.

transform_affine(values)[source]#

Apply only the affine part of this transformation on thegiven array of values.

transform(values) is always equivalent totransform_affine(transform_non_affine(values)).

In non-affine transformations, this is generally a no-op. Inaffine transformations, this is equivalent totransform(values).

Parameters:
valuesarray

The input values as an array of lengthinput_dims orshape (N,input_dims).

Returns:
array

The output values as an array of lengthoutput_dims orshape (N,output_dims), depending on the input.

transform_non_affine(values)[source]#

Apply only the non-affine part of this transformation.

transform(values) is always equivalent totransform_affine(transform_non_affine(values)).

In non-affine transformations, this is generally equivalent totransform(values). In affine transformations, this isalways a no-op.

Parameters:
valuesarray

The input values as an array of lengthinput_dims orshape (N,input_dims).

Returns:
array

The output values as an array of lengthoutput_dims orshape (N,output_dims), depending on the input.

transform_path(path)[source]#

Apply the transform toPathpath, returning a newPath.

In some cases, this transform may insert curves into the paththat began as line segments.

transform_path_affine(path)[source]#

Apply the affine part of this transform toPathpath, returning anewPath.

transform_path(path) is equivalent totransform_path_affine(transform_path_non_affine(values)).

transform_path_non_affine(path)[source]#

Apply the non-affine part of this transform toPathpath,returning a newPath.

transform_path(path) is equivalent totransform_path_affine(transform_path_non_affine(values)).

classmatplotlib.transforms.LockableBbox(bbox,x0=None,y0=None,x1=None,y1=None,**kwargs)[source]#

Bases:BboxBase

ABbox where some elements may be locked at certain values.

When the child bounding box changes, the bounds of this bbox will updateaccordingly with the exception of the locked elements.

Parameters:
bboxBbox

The child bounding box to wrap.

x0float or None

The locked value for x0, or None to leave unlocked.

y0float or None

The locked value for y0, or None to leave unlocked.

x1float or None

The locked value for x1, or None to leave unlocked.

y1float or None

The locked value for y1, or None to leave unlocked.

get_points()[source]#
propertylocked_x0#

float or None: The value used for the locked x0.

propertylocked_x1#

float or None: The value used for the locked x1.

propertylocked_y0#

float or None: The value used for the locked y0.

propertylocked_y1#

float or None: The value used for the locked y1.

classmatplotlib.transforms.ScaledTranslation(xt,yt,scale_trans,**kwargs)[source]#

Bases:Affine2DBase

A transformation that translates byxt andyt, afterxt andythave been transformed byscale_trans.

Parameters:
shorthand_namestr

A string representing the "name" of the transform. The name carriesno significance other than to improve the readability ofstr(transform) when DEBUG=True.

get_matrix()[source]#

Get the matrix for the affine part of this transform.

classmatplotlib.transforms.Transform(shorthand_name=None)[source]#

Bases:TransformNode

The base class of allTransformNode instances thatactually perform a transformation.

All non-affine transformations should be subclasses of this class.New affine transformations should be subclasses ofAffine2D.

Subclasses of this class should override the following members (atminimum):

The following attributes may be overridden if the default is unsuitable:

If the transform needs to do something non-standard withmatplotlib.path.Path objects, such as adding curveswhere there were once line segments, it should override:

Parameters:
shorthand_namestr

A string representing the "name" of the transform. The name carriesno significance other than to improve the readability ofstr(transform) when DEBUG=True.

__add__(other)[source]#

Compose two transforms together so thatself is followed byother.

A+B returns a transformC so thatC.transform(x)==B.transform(A.transform(x)).

__sub__(other)[source]#

Composeself with the inverse ofother, cancelling identical termsif any:

# In general:A-B==A+B.inverted()# (but see note regarding frozen transforms below).# If A "ends with" B (i.e. A == A' + B for some A') we can cancel# out B:(A' + B) - B == A'# Likewise, if B "starts with" A (B = A + B'), we can cancel out A:A-(A+B') == B'.inverted()==B'^-1

Cancellation (rather than naively returningA+B.inverted()) isimportant for multiple reasons:

  • It avoids floating-point inaccuracies when computing the inverse ofB:B-B is guaranteed to cancel out exactly (resulting in theidentity transform), whereasB+B.inverted() may differ by asmall epsilon.

  • B.inverted() always returns a frozen transform: if one computesA+B+B.inverted() and later mutatesB, thenB.inverted() won't be updated and the last two terms won't cancelout anymore; on the other hand,A+B-B will always be equal toA even ifB is mutated.

contains_branch(other)[source]#

Return whether the given transform is a sub-tree of this transform.

This routine uses transform equality to identify sub-trees, thereforein many situations it is object id which will be used.

For the case where the given transform represents the wholeof this transform, returns True.

contains_branch_seperately(other_transform)[source]#

Return whether the given branch is a sub-tree of this transform oneach separate dimension.

A common use for this method is to identify if a transform is a blendedtransform containing an Axes' data transform. e.g.:

x_isdata,y_isdata=trans.contains_branch_seperately(ax.transData)
propertydepth#

Return the number of transforms which have been chainedtogether to form this Transform instance.

Note

For the special case of a Composite transform, the maximum depthof the two is returned.

get_affine()[source]#

Get the affine part of this transform.

get_matrix()[source]#

Get the matrix for the affine part of this transform.

has_inverse=False#

True if this transform has a corresponding inverse transform.

input_dims=None#

The number of input dimensions of this transform.Must be overridden (with integers) in the subclass.

inverted()[source]#

Return the corresponding inverse transformation.

It holdsx==self.inverted().transform(self.transform(x)).

The return value of this method should be treated astemporary. An update toself does not cause a correspondingupdate to its inverted copy.

is_separable=False#

True if this transform is separable in the x- and y- dimensions.

output_dims=None#

The number of output dimensions of this transform.Must be overridden (with integers) in the subclass.

transform(values)[source]#

Apply this transformation on the given array ofvalues.

Parameters:
valuesarray-like

The input values as an array of lengthinput_dims orshape (N,input_dims).

Returns:
array

The output values as an array of lengthoutput_dims orshape (N,output_dims), depending on the input.

transform_affine(values)[source]#

Apply only the affine part of this transformation on thegiven array of values.

transform(values) is always equivalent totransform_affine(transform_non_affine(values)).

In non-affine transformations, this is generally a no-op. Inaffine transformations, this is equivalent totransform(values).

Parameters:
valuesarray

The input values as an array of lengthinput_dims orshape (N,input_dims).

Returns:
array

The output values as an array of lengthoutput_dims orshape (N,output_dims), depending on the input.

transform_angles(angles,pts,radians=False,pushoff=1e-05)[source]#

Transform a set of angles anchored at specific locations.

Parameters:
angles(N,) array-like

The angles to transform.

pts(N, 2) array-like

The points where the angles are anchored.

radiansbool, default: False

Whetherangles are radians or degrees.

pushofffloat

For each point inpts and angle inangles, the transformedangle is computed by transforming a segment of lengthpushoffstarting at that point and making that angle relative to thehorizontal axis, and measuring the angle between the horizontalaxis and the transformed segment.

Returns:
(N,) array
transform_bbox(bbox)[source]#

Transform the given bounding box.

For smarter transforms including caching (a common requirement inMatplotlib), seeTransformedBbox.

transform_non_affine(values)[source]#

Apply only the non-affine part of this transformation.

transform(values) is always equivalent totransform_affine(transform_non_affine(values)).

In non-affine transformations, this is generally equivalent totransform(values). In affine transformations, this isalways a no-op.

Parameters:
valuesarray

The input values as an array of lengthinput_dims orshape (N,input_dims).

Returns:
array

The output values as an array of lengthoutput_dims orshape (N,output_dims), depending on the input.

transform_path(path)[source]#

Apply the transform toPathpath, returning a newPath.

In some cases, this transform may insert curves into the paththat began as line segments.

transform_path_affine(path)[source]#

Apply the affine part of this transform toPathpath, returning anewPath.

transform_path(path) is equivalent totransform_path_affine(transform_path_non_affine(values)).

transform_path_non_affine(path)[source]#

Apply the non-affine part of this transform toPathpath,returning a newPath.

transform_path(path) is equivalent totransform_path_affine(transform_path_non_affine(values)).

transform_point(point)[source]#

Return a transformed point.

This function is only kept for backcompatibility; the more generaltransform method is capable of transforming both a list of pointsand a single point.

The point is given as a sequence of lengthinput_dims.The transformed point is returned as a sequence of lengthoutput_dims.

classmatplotlib.transforms.TransformNode(shorthand_name=None)[source]#

Bases:object

The base class for anything that participates in the transform treeand needs to invalidate its parents or be invalidated. This includesclasses that are not really transforms, such as bounding boxes, since sometransforms depend on bounding boxes to compute their values.

Parameters:
shorthand_namestr

A string representing the "name" of the transform. The name carriesno significance other than to improve the readability ofstr(transform) when DEBUG=True.

frozen()[source]#

Return a frozen copy of this transform node. The frozen copy will notbe updated when its children change. Useful for storing a previouslyknown state of a transform wherecopy.deepcopy() might normally beused.

invalidate()[source]#

Invalidate thisTransformNode and triggers an invalidation of itsancestors. Should be called any time the transform changes.

is_affine=False#
is_bbox=False#
pass_through=False#

If pass_through is True, all ancestors will always beinvalidated, even if 'self' is already invalid.

set_children(*children)[source]#

Set the children of the transform, to let the invalidationsystem know which transforms can invalidate this transform.Should be called from the constructor of any transforms thatdepend on other transforms.

classmatplotlib.transforms.TransformWrapper(child)[source]#

Bases:Transform

A helper class that holds a single child transform and actsequivalently to it.

This is useful if a node of the transform tree must be replaced atrun time with a transform of a different type. This class allowsthat replacement to correctly trigger invalidation.

TransformWrapper instances must have the same input and output dimensionsduring their entire lifetime, so the child transform may only be replacedwith another child transform of the same dimensions.

child: ATransform instance. This child may laterbe replaced withset().

frozen()[source]#

Return a frozen copy of this transform node. The frozen copy will notbe updated when its children change. Useful for storing a previouslyknown state of a transform wherecopy.deepcopy() might normally beused.

propertyhas_inverse#

Returns True when the argument is true, False otherwise.The builtins True and False are the only two instances of the class bool.The class bool is a subclass of the class int, and cannot be subclassed.

propertyinput_dims#

The type of the None singleton.

propertyis_affine#

Returns True when the argument is true, False otherwise.The builtins True and False are the only two instances of the class bool.The class bool is a subclass of the class int, and cannot be subclassed.

propertyis_separable#

Returns True when the argument is true, False otherwise.The builtins True and False are the only two instances of the class bool.The class bool is a subclass of the class int, and cannot be subclassed.

propertyoutput_dims#

The type of the None singleton.

pass_through=True#

If pass_through is True, all ancestors will always beinvalidated, even if 'self' is already invalid.

set(child)[source]#

Replace the current child of this transform with another one.

The new child must have the same number of input and outputdimensions as the current child.

classmatplotlib.transforms.TransformedBbox(bbox,transform,**kwargs)[source]#

Bases:BboxBase

ABbox that is automatically transformed by a giventransform. When either the child bounding box or transformchanges, the bounds of this bbox will update accordingly.

Parameters:
bboxBbox
transformTransform
contains(x,y)[source]#

Return whether(x,y) is in the bounding box or on its edge.

fully_contains(x,y)[source]#

Return whetherx,y is in the bounding box, but not on its edge.

get_points()[source]#
classmatplotlib.transforms.TransformedPatchPath(patch)[source]#

Bases:TransformedPath

ATransformedPatchPath caches a non-affine transformed copy of thePatch. This cached copy is automatically updated when thenon-affine part of the transform or the patch changes.

Parameters:
patchPatch
classmatplotlib.transforms.TransformedPath(path,transform)[source]#

Bases:TransformNode

ATransformedPath caches a non-affine transformed copy of thePath. This cached copy is automatically updated when thenon-affine part of the transform changes.

Note

Paths are considered immutable by this class. Any update to thepath's vertices/codes will not trigger a transform recomputation.

Parameters:
pathPath
transformTransform
get_affine()[source]#
get_fully_transformed_path()[source]#

Return a fully-transformed copy of the child path.

get_transformed_path_and_affine()[source]#

Return a copy of the child path, with the non-affine part ofthe transform already applied, along with the affine part ofthe path necessary to complete the transformation.

get_transformed_points_and_affine()[source]#

Return a copy of the child path, with the non-affine part ofthe transform already applied, along with the affine part ofthe path necessary to complete the transformation. Unlikeget_transformed_path_and_affine(), no interpolation willbe performed.

matplotlib.transforms.blended_transform_factory(x_transform,y_transform)[source]#

Create a new "blended" transform usingx_transform to transformthex-axis andy_transform to transform they-axis.

A faster version of the blended transform is returned for the casewhere both child transforms are affine.

matplotlib.transforms.composite_transform_factory(a,b)[source]#

Create a new composite transform that is the result of applyingtransform a then transform b.

Shortcut versions of the blended transform are provided for thecase where both child transforms are affine, or one or the otheris the identity transform.

Composite transforms may also be created using the '+' operator,e.g.:

c=a+b
matplotlib.transforms.interval_contains(interval,val)[source]#

Check, inclusively, whether an interval includes a given value.

Parameters:
interval(float, float)

The endpoints of the interval.

valfloat

Value to check is within interval.

Returns:
bool

Whetherval is within theinterval.

matplotlib.transforms.interval_contains_open(interval,val)[source]#

Check, excluding endpoints, whether an interval includes a given value.

Parameters:
interval(float, float)

The endpoints of the interval.

valfloat

Value to check is within interval.

Returns:
bool

Whetherval is within theinterval.

matplotlib.transforms.nonsingular(vmin,vmax,expander=0.001,tiny=1e-15,increasing=True)[source]#

Modify the endpoints of a range as needed to avoid singularities.

Parameters:
vmin, vmaxfloat

The initial endpoints.

expanderfloat, default: 0.001

Fractional amount by whichvmin andvmax are expanded ifthe original interval is too small, based ontiny.

tinyfloat, default: 1e-15

Threshold for the ratio of the interval to the maximum absolutevalue of its endpoints. If the interval is smaller thanthis, it will be expanded. This value should be around1e-15 or larger; otherwise the interval will be approachingthe double precision resolution limit.

increasingbool, default: True

If True, swapvmin,vmax ifvmin >vmax.

Returns:
vmin, vmaxfloat

Endpoints, expanded and/or swapped if necessary.If either input is inf or NaN, or if both inputs are 0 or veryclose to zero, it returns -expander,expander.

matplotlib.transforms.offset_copy(trans,fig=None,x=0.0,y=0.0,units='inches')[source]#

Return a new transform with an added offset.

Parameters:
transTransform subclass

Any transform, to which offset will be applied.

figFigure, default: None

Current figure. It can be None ifunits are 'dots'.

x, yfloat, default: 0.0

The offset to apply.

units{'inches', 'points', 'dots'}, default: 'inches'

Units of the offset.

Returns:
Transform subclass

Transform with applied offset.

On this page