matplotlib.patheffects#

Defines classes for path effects. The path effects are supported inText,Line2D andPatch.

classmatplotlib.patheffects.AbstractPathEffect(offset=(0.0,0.0))[source]#

Bases:object

A base class for path effects.

Subclasses should override thedraw_path method to add effectfunctionality.

Parameters:
offset(float, float), default: (0, 0)

The (x, y) offset to apply to the path, measured in points.

draw_path(renderer,gc,tpath,affine,rgbFace=None)[source]#

Derived should override this method. The arguments are the sameasmatplotlib.backend_bases.RendererBase.draw_path()except the first argument is a renderer.

classmatplotlib.patheffects.Normal(offset=(0.0,0.0))[source]#

Bases:AbstractPathEffect

The "identity" PathEffect.

The Normal PathEffect's sole purpose is to draw the original artist withno special path effect.

Parameters:
offset(float, float), default: (0, 0)

The (x, y) offset to apply to the path, measured in points.

classmatplotlib.patheffects.PathEffectRenderer(path_effects,renderer)[source]#

Bases:RendererBase

Implements a Renderer which contains another renderer.

This proxy then intercepts draw calls, calling the appropriateAbstractPathEffect draw method.

Note

Not all methods have been overridden on this RendererBase subclass.It may be necessary to add further methods to extend the PathEffectscapabilities further.

Parameters:
path_effectsiterable ofAbstractPathEffect

The path effects which this renderer represents.

rendererRendererBase subclass
close_group(s)[source]#

Close a grouping element with labels.

Only used by the SVG renderer.

copy_with_path_effect(path_effects)[source]#
draw_markers(gc,marker_path,marker_trans,path,*args,**kwargs)[source]#

Draw a marker at each ofpath's vertices (excluding control points).

The base (fallback) implementation makes multiple calls todraw_path.Backends may want to override this method in order to draw the markeronly once and reuse it multiple times.

Parameters:
gcGraphicsContextBase

The graphics context.

marker_pathPath

The path for the marker.

marker_transTransform

An affine transform applied to the marker.

pathPath

The locations to draw the markers.

transTransform

An affine transform applied to the path.

rgbFacecolor, optional
draw_path(gc,tpath,affine,rgbFace=None)[source]#

Draw aPath instance using the given affine transform.

draw_path_collection(gc,master_transform,paths,*args,**kwargs)[source]#

Draw a collection ofpaths.

Each path is first transformed by the corresponding entryinall_transforms (a list of (3, 3) matrices) and then bymaster_transform. They are then translated by the correspondingentry inoffsets, which has been first transformed byoffset_trans.

facecolors,edgecolors,linewidths,linestyles,antialiasedandhatchcolors are lists that set the corresponding properties.

Added in version 3.11:Allowhatchcolors to be specified.

offset_position is unused now, but the argument is kept forbackwards compatibility.

The base (fallback) implementation makes multiple calls todraw_path.Backends may want to override this in order to render each set ofpath data only once, and then reference that path multiple times withthe different offsets, colors, styles etc. The generator methods_iter_collection_raw_paths and_iter_collection are provided tohelp with (and standardize) the implementation across backends. Itis highly recommended to use those generators, so that changes to thebehavior ofdraw_path_collection can be made globally.

open_group(s,gid=None)[source]#

Open a grouping element with labels andgid (if set) as id.

Only used by the SVG renderer.

classmatplotlib.patheffects.PathPatchEffect(offset=(0,0),**kwargs)[source]#

Bases:AbstractPathEffect

Draws aPathPatch instance whose Path comes from the originalPathEffect artist.

Parameters:
offset(float, float), default: (0, 0)

The (x, y) offset to apply to the path, in points.

**kwargs

All keyword arguments are passed through to thePathPatch constructor. Theproperties which cannot be overridden are "path", "clip_box""transform" and "clip_path".

draw_path(renderer,gc,tpath,affine,rgbFace)[source]#

Derived should override this method. The arguments are the sameasmatplotlib.backend_bases.RendererBase.draw_path()except the first argument is a renderer.

classmatplotlib.patheffects.SimpleLineShadow(offset=(2,-2),shadow_color='k',alpha=0.3,rho=0.3,**kwargs)[source]#

Bases:AbstractPathEffect

A simple shadow via a line.

Parameters:
offset(float, float), default: (2, -2)

The (x, y) offset to apply to the path, in points.

shadow_colorcolor, default: 'black'

The shadow color.A value ofNone takes the original artist's colorwith a scale factor ofrho.

alphafloat, default: 0.3

The alpha transparency of the created shadow patch.

rhofloat, default: 0.3

A scale factor to apply to the rgbFace color ifshadow_colorisNone.

**kwargs

Extra keywords are stored and passed through toAbstractPathEffect._update_gc().

draw_path(renderer,gc,tpath,affine,rgbFace)[source]#

Overrides the standard draw_path to add the shadow offset andnecessary color changes for the shadow.

classmatplotlib.patheffects.SimplePatchShadow(offset=(2,-2),shadow_rgbFace=None,alpha=None,rho=0.3,**kwargs)[source]#

Bases:AbstractPathEffect

A simple shadow via a filled patch.

Parameters:
offset(float, float), default: (2, -2)

The (x, y) offset of the shadow in points.

shadow_rgbFacecolor

The shadow color.

alphafloat, default: 0.3

The alpha transparency of the created shadow patch.

rhofloat, default: 0.3

A scale factor to apply to the rgbFace color ifshadow_rgbFaceis not specified.

**kwargs

Extra keywords are stored and passed through toAbstractPathEffect._update_gc().

draw_path(renderer,gc,tpath,affine,rgbFace)[source]#

Overrides the standard draw_path to add the shadow offset andnecessary color changes for the shadow.

classmatplotlib.patheffects.Stroke(offset=(0,0),**kwargs)[source]#

Bases:AbstractPathEffect

A line based PathEffect which re-draws a stroke.

The path will be stroked with its gc updated with the givenkeyword arguments, i.e., the keyword arguments should be validgc parameter values.

draw_path(renderer,gc,tpath,affine,rgbFace)[source]#

Draw the path with updated gc.

classmatplotlib.patheffects.TickedStroke(offset=(0,0),spacing=10.0,angle=45.0,length=np.float64(1.4142135623730951),**kwargs)[source]#

Bases:AbstractPathEffect

A line-based PathEffect which draws a path with a ticked style.

This line style is frequently used to represent constraints inoptimization. The ticks may be used to indicate that one sideof the line is invalid or to represent a closed boundary of adomain (i.e. a wall or the edge of a pipe).

The spacing, length, and angle of ticks can be controlled.

This line style is sometimes referred to as a hatched line.

See also theTickedStroke patheffect example.

Parameters:
offset(float, float), default: (0, 0)

The (x, y) offset to apply to the path, in points.

spacingfloat, default: 10.0

The spacing between ticks in points.

anglefloat, default: 45.0

The angle between the path and the tick in degrees. The angleis measured as if you were an ant walking along the curve, withzero degrees pointing directly ahead, 90 to your left, -90to your right, and 180 behind you. To change side of the ticks,change sign of the angle.

lengthfloat, default: 1.414

The length of the tick relative to spacing.Recommended length = 1.414 (sqrt(2)) when angle=45, length=1.0when angle=90 and length=2.0 when angle=60.

**kwargs

Extra keywords are stored and passed through toAbstractPathEffect._update_gc().

Examples

SeeTickedStroke patheffect.

draw_path(renderer,gc,tpath,affine,rgbFace)[source]#

Draw the path with updated gc.

classmatplotlib.patheffects.withSimplePatchShadow(offset=(2,-2),shadow_rgbFace=None,alpha=None,rho=0.3,**kwargs)[source]#

Bases:SimplePatchShadow

A shortcut PathEffect for applyingSimplePatchShadow and thendrawing the original Artist.

With this class you can use

artist.set_path_effects([patheffects.withSimplePatchShadow()])

as a shortcut for

artist.set_path_effects([patheffects.SimplePatchShadow(),patheffects.Normal()])
Parameters:
offset(float, float), default: (2, -2)

The (x, y) offset of the shadow in points.

shadow_rgbFacecolor

The shadow color.

alphafloat, default: 0.3

The alpha transparency of the created shadow patch.

rhofloat, default: 0.3

A scale factor to apply to the rgbFace color ifshadow_rgbFaceis not specified.

**kwargs

Extra keywords are stored and passed through toAbstractPathEffect._update_gc().

draw_path(renderer,gc,tpath,affine,rgbFace)[source]#

Overrides the standard draw_path to add the shadow offset andnecessary color changes for the shadow.

classmatplotlib.patheffects.withStroke(offset=(0,0),**kwargs)[source]#

Bases:Stroke

A shortcut PathEffect for applyingStroke and thendrawing the original Artist.

With this class you can use

artist.set_path_effects([patheffects.withStroke()])

as a shortcut for

artist.set_path_effects([patheffects.Stroke(),patheffects.Normal()])

The path will be stroked with its gc updated with the givenkeyword arguments, i.e., the keyword arguments should be validgc parameter values.

draw_path(renderer,gc,tpath,affine,rgbFace)[source]#

Draw the path with updated gc.

classmatplotlib.patheffects.withTickedStroke(offset=(0,0),spacing=10.0,angle=45.0,length=np.float64(1.4142135623730951),**kwargs)[source]#

Bases:TickedStroke

A shortcut PathEffect for applyingTickedStroke and thendrawing the original Artist.

With this class you can use

artist.set_path_effects([patheffects.withTickedStroke()])

as a shortcut for

artist.set_path_effects([patheffects.TickedStroke(),patheffects.Normal()])
Parameters:
offset(float, float), default: (0, 0)

The (x, y) offset to apply to the path, in points.

spacingfloat, default: 10.0

The spacing between ticks in points.

anglefloat, default: 45.0

The angle between the path and the tick in degrees. The angleis measured as if you were an ant walking along the curve, withzero degrees pointing directly ahead, 90 to your left, -90to your right, and 180 behind you. To change side of the ticks,change sign of the angle.

lengthfloat, default: 1.414

The length of the tick relative to spacing.Recommended length = 1.414 (sqrt(2)) when angle=45, length=1.0when angle=90 and length=2.0 when angle=60.

**kwargs

Extra keywords are stored and passed through toAbstractPathEffect._update_gc().

Examples

SeeTickedStroke patheffect.

draw_path(renderer,gc,tpath,affine,rgbFace)[source]#

Draw the path with updated gc.