matplotlib.spines#

classmatplotlib.spines.Spine(axes,spine_type,path,**kwargs)[source]#

Bases:Patch

An axis spine -- the line noting the data area boundaries.

Spines are the lines connecting the axis tick marks and noting theboundaries of the data area. They can be placed at arbitrarypositions. Seeset_position for more information.

The default position is('outward',0).

Spines are subclasses ofPatch, and inherit much of their behavior.

Spines draw a line, a circle, or an arc depending on ifset_patch_line,set_patch_circle, orset_patch_arc has been called. Line-like is the default.

For examples seeSpines.

Parameters:
axesAxes

TheAxes instance containing the spine.

spine_typestr

The spine type.

pathPath

ThePath instance used to draw the spine.

Other Parameters:
**kwargs

Valid keyword arguments are:

Property

Description

agg_filter

a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array and two offsets from the bottom left corner of the image

alpha

unknown

animated

bool

antialiased oraa

bool or None

capstyle

CapStyle or {'butt', 'projecting', 'round'}

clip_box

BboxBase or None

clip_on

bool

clip_path

Patch or (Path, Transform) or None

color

color

edgecolor orec

color or None

facecolor orfc

color or None

figure

Figure orSubFigure

fill

bool

gid

str

hatch

{'/', '\', '|', '-', '+', 'x', 'o', 'O', '.', '*'}

hatch_linewidth

unknown

hatchcolor

color or 'edge' or None

in_layout

bool

joinstyle

JoinStyle or {'miter', 'round', 'bevel'}

label

object

linestyle orls

{'-', '--', '-.', ':', '', (offset, on-off-seq), ...}

linewidth orlw

float or None

mouseover

bool

path_effects

list ofAbstractPathEffect

picker

None or bool or float or callable

rasterized

bool

sketch_params

(scale: float, length: float, randomness: float)

snap

bool or None

transform

Transform

url

str

visible

bool

zorder

float

classmethodarc_spine(axes,spine_type,center,radius,theta1,theta2,**kwargs)[source]#

Create and return an arcSpine.

classmethodcircular_spine(axes,center,radius,**kwargs)[source]#

Create and return a circularSpine.

clear()[source]#

Clear the current spine.

draw(renderer)[source]#

Draw the Artist (and its children) using the given renderer.

This has no effect if the artist is not visible (Artist.get_visiblereturns False).

Parameters:
rendererRendererBase subclass.

Notes

This method is overridden in the Artist subclasses.

get_bounds()[source]#

Get the bounds of the spine.

get_patch_transform()[source]#

Return theTransform instance mapping patch coordinatesto data coordinates.

For example, one may define a patch of a circle which represents aradius of 5 by providing coordinates for a unit circle, and atransform which scales the coordinates (the patch coordinate) by 5.

get_path()[source]#

Return the path of this patch.

get_position()[source]#

Return the spine position.

get_spine_transform()[source]#

Return the spine transform.

get_window_extent(renderer=None)[source]#

Return the window extent of the spines in display space, includingpadding for ticks (but not their labels)

classmethodlinear_spine(axes,spine_type,**kwargs)[source]#

Create and return a linearSpine.

register_axis(axis)[source]#

Register an axis.

An axis should be registered with its corresponding spine fromthe Axes instance. This allows the spine to clear any axisproperties when needed.

set(*,agg_filter=<UNSET>,alpha=<UNSET>,animated=<UNSET>,antialiased=<UNSET>,bounds=<UNSET>,capstyle=<UNSET>,clip_box=<UNSET>,clip_on=<UNSET>,clip_path=<UNSET>,color=<UNSET>,edgecolor=<UNSET>,facecolor=<UNSET>,fill=<UNSET>,gid=<UNSET>,hatch=<UNSET>,hatch_linewidth=<UNSET>,hatchcolor=<UNSET>,in_layout=<UNSET>,joinstyle=<UNSET>,label=<UNSET>,linestyle=<UNSET>,linewidth=<UNSET>,mouseover=<UNSET>,patch_arc=<UNSET>,patch_circle=<UNSET>,path_effects=<UNSET>,picker=<UNSET>,position=<UNSET>,rasterized=<UNSET>,sketch_params=<UNSET>,snap=<UNSET>,transform=<UNSET>,url=<UNSET>,visible=<UNSET>,zorder=<UNSET>)[source]#

Set multiple properties at once.

Supported properties are

Property

Description

agg_filter

a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array and two offsets from the bottom left corner of the image

alpha

float or None

animated

bool

antialiased oraa

bool or None

bounds

(low: float, high: float)

capstyle

CapStyle or {'butt', 'projecting', 'round'}

clip_box

BboxBase or None

clip_on

bool

clip_path

Patch or (Path, Transform) or None

color

color

edgecolor orec

color or None

facecolor orfc

color or None

figure

Figure orSubFigure

fill

bool

gid

str

hatch

{'/', '\', '|', '-', '+', 'x', 'o', 'O', '.', '*'}

hatch_linewidth

unknown

hatchcolor

color or 'edge' or None

in_layout

bool

joinstyle

JoinStyle or {'miter', 'round', 'bevel'}

label

object

linestyle orls

{'-', '--', '-.', ':', '', (offset, on-off-seq), ...}

linewidth orlw

float or None

mouseover

bool

patch_arc

unknown

patch_circle

unknown

path_effects

list ofAbstractPathEffect

picker

None or bool or float or callable

position

unknown

rasterized

bool

sketch_params

(scale: float, length: float, randomness: float)

snap

bool or None

transform

Transform

url

str

visible

bool

zorder

float

set_bounds(low=None,high=None)[source]#

Set the spine bounds.

Parameters:
lowfloat or None, optional

The lower spine bound. PassingNone leaves the limit unchanged.

The bounds may also be passed as the tuple (low,high) as thefirst positional argument.

highfloat or None, optional

The higher spine bound. PassingNone leaves the limit unchanged.

set_color(c)[source]#

Set the edgecolor.

Parameters:
ccolor

Notes

This method does not modify the facecolor (which defaults to "none"),unlike thePatch.set_color method defined in the parent class. UsePatch.set_facecolor to set the facecolor.

set_patch_arc(center,radius,theta1,theta2)[source]#

Set the spine to be arc-like.

set_patch_circle(center,radius)[source]#

Set the spine to be circular.

set_patch_line()[source]#

Set the spine to be linear.

set_position(position)[source]#

Set the position of the spine.

Spine position is specified by a 2 tuple of (position type,amount). The position types are:

  • 'outward': place the spine out from the data area by the specifiednumber of points. (Negative values place the spine inwards.)

  • 'axes': place the spine at the specified Axes coordinate (0 to 1).

  • 'data': place the spine at the specified data coordinate.

Additionally, shorthand notations define a special positions:

  • 'center' ->('axes',0.5)

  • 'zero' ->('data',0.0)

Examples

Spine placement

classmatplotlib.spines.Spines(**kwargs)[source]#

Bases:MutableMapping

The container of allSpines in an Axes.

The interface is dict-like mapping names (e.g. 'left') toSpine objects.Additionally, it implements some pandas.Series-like features like accessingelements by attribute:

spines['top'].set_visible(False)spines.top.set_visible(False)

Multiple spines can be addressed simultaneously by passing a list:

spines[['top','right']].set_visible(False)

Use an open slice to address all spines:

spines[:].set_visible(False)

The latter two indexing methods will return aSpinesProxy that broadcasts allset_*() andset() calls to its members, but cannot be used for any otheroperation.

classmethodfrom_dict(d)[source]#
classmatplotlib.spines.SpinesProxy(spine_dict)[source]#

Bases:object

A proxy to broadcastset_*() andset() method calls to containedSpines.

The proxy cannot be used for any other operations on its members.

The supported methods are determined dynamically based on the containedspines. If not all spines support a given method, it's executed only onthe subset of spines that support it.