matplotlib.lines.Line2D#

classmatplotlib.lines.Line2D(xdata,ydata,*,linewidth=None,linestyle=None,color=None,gapcolor=None,marker=None,markersize=None,markeredgewidth=None,markeredgecolor=None,markerfacecolor=None,markerfacecoloralt='none',fillstyle=None,antialiased=None,dash_capstyle=None,solid_capstyle=None,dash_joinstyle=None,solid_joinstyle=None,pickradius=5,drawstyle=None,markevery=None,**kwargs)[source]#

Bases:Artist

A line - the line can have both a solid linestyle connecting allthe vertices, and a marker at each vertex. Additionally, thedrawing of the solid line is influenced by the drawstyle, e.g., onecan create "stepped" lines in various styles.

Create aLine2D instance withx andy data in sequences ofxdata,ydata.

Additional keyword arguments areLine2D properties:

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

clip_box

BboxBase or None

clip_on

bool

clip_path

Patch or (Path, Transform) or None

color orc

color

dash_capstyle

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

dash_joinstyle

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

dashes

sequence of floats (on/off ink in points) or (None, None)

data

(2, N) array or two 1D arrays

drawstyle ords

{'default', 'steps', 'steps-pre', 'steps-mid', 'steps-post'}, default: 'default'

figure

Figure orSubFigure

fillstyle

{'full', 'left', 'right', 'bottom', 'top', 'none'}

gapcolor

color or None

gid

str

in_layout

bool

label

object

linestyle orls

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

linewidth orlw

float

marker

marker style string,Path orMarkerStyle

markeredgecolor ormec

color

markeredgewidth ormew

float

markerfacecolor ormfc

color

markerfacecoloralt ormfcalt

color

markersize orms

float

markevery

None or int or (int, int) or slice or list[int] or float or (float, float) or list[bool]

mouseover

bool

path_effects

list ofAbstractPathEffect

picker

float or callable[[Artist, Event], tuple[bool, dict]]

pickradius

float

rasterized

bool

sketch_params

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

snap

bool or None

solid_capstyle

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

solid_joinstyle

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

transform

unknown

url

str

visible

bool

xdata

1D array

ydata

1D array

zorder

float

Seeset_linestyle() for a description of the line styles,set_marker() for a description of the markers, andset_drawstyle() for a description of the draw styles.

contains(mouseevent)[source]#

Test whethermouseevent occurred on the line.

An event is deemed to have occurred "on" the line if it is lessthanself.pickradius (default: 5 points) away from it. Useget_pickradius orset_pickradius to get or setthe pick radius.

Parameters:
mouseeventMouseEvent
Returns:
containsbool

Whether any values are within the radius.

detailsdict

A dictionary{'ind':pointlist}, wherepointlist is alist of points of the line that are within the pickradius aroundthe event position.

TODO: sort returned indices by distance

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.

drawStyleKeys=['default','steps-mid','steps-pre','steps-post','steps']#
drawStyles={'default':'_draw_lines','steps':'_draw_steps_pre','steps-mid':'_draw_steps_mid','steps-post':'_draw_steps_post','steps-pre':'_draw_steps_pre'}#
fillStyles=('full','left','right','bottom','top','none')#
filled_markers=('.','o','v','^','<','>','8','s','p','*','h','H','D','d','P','X')#
get_aa()[source]#

Alias forget_antialiased.

get_antialiased()[source]#

Return whether antialiased rendering is used.

get_bbox()[source]#

Get the bounding box of this line.

get_c()[source]#

Alias forget_color.

get_color()[source]#

Return the line color.

See alsoset_color.

get_dash_capstyle()[source]#

Return theCapStyle for dashed lines.

See alsoset_dash_capstyle.

get_dash_joinstyle()[source]#

Return theJoinStyle for dashed lines.

See alsoset_dash_joinstyle.

get_data(orig=True)[source]#

Return the line data as an(xdata,ydata) pair.

Iforig isTrue, return the original data.

get_drawstyle()[source]#

Return the drawstyle.

See alsoset_drawstyle.

get_ds()[source]#

Alias forget_drawstyle.

get_fillstyle()[source]#

Return the marker fill style.

See alsoset_fillstyle.

get_gapcolor()[source]#

Return the line gapcolor.

See alsoset_gapcolor.

get_linestyle()[source]#

Return the linestyle.

See alsoset_linestyle.

get_linewidth()[source]#

Return the linewidth in points.

See alsoset_linewidth.

get_ls()[source]#

Alias forget_linestyle.

get_lw()[source]#

Alias forget_linewidth.

get_marker()[source]#

Return the line marker.

See alsoset_marker.

get_markeredgecolor()[source]#

Return the marker edge color.

See alsoset_markeredgecolor.

get_markeredgewidth()[source]#

Return the marker edge width in points.

See alsoset_markeredgewidth.

get_markerfacecolor()[source]#

Return the marker face color.

See alsoset_markerfacecolor.

get_markerfacecoloralt()[source]#

Return the alternate marker face color.

See alsoset_markerfacecoloralt.

get_markersize()[source]#

Return the marker size in points.

See alsoset_markersize.

get_markevery()[source]#

Return the markevery setting for marker subsampling.

See alsoset_markevery.

get_mec()[source]#

Alias forget_markeredgecolor.

get_mew()[source]#

Alias forget_markeredgewidth.

get_mfc()[source]#

Alias forget_markerfacecolor.

get_mfcalt()[source]#

Alias forget_markerfacecoloralt.

get_ms()[source]#

Alias forget_markersize.

get_path()[source]#

Return thePath associated with this line.

get_pickradius()[source]#

Return the pick radius used for containment tests.

Seecontains for more details.

get_solid_capstyle()[source]#

Return theCapStyle for solid lines.

See alsoset_solid_capstyle.

get_solid_joinstyle()[source]#

Return theJoinStyle for solid lines.

See alsoset_solid_joinstyle.

get_window_extent(renderer=None)[source]#

Get the artist's bounding box in display space.

The bounding box's width and height are non-negative.

Subclasses should override for inclusion in the bounding box"tight" calculation. Default is to return an empty boundingbox at 0, 0.

Warning

The extent can change due to any changes in the transform stack, suchas changing the Axes limits, the figure size, the canvas used (as isdone when saving a figure), or the DPI.

Relying on a once-retrieved window extent can lead to unexpectedbehavior in various cases such as interactive figures being resized ormoved to a screen with different dpi, or figures that look fine onscreen render incorrectly when saved to file.

To get accurate results you may need to manually callmatplotlib.figure.Figure.savefig ormatplotlib.figure.Figure.draw_without_rendering to have Matplotlibcompute the rendered size.

get_xdata(orig=True)[source]#

Return the xdata.

Iforig isTrue, return the original data, else theprocessed data.

get_xydata()[source]#

Return thexy data as a (N, 2) array.

get_ydata(orig=True)[source]#

Return the ydata.

Iforig isTrue, return the original data, else theprocessed data.

is_dashed()[source]#

Return whether line has a dashed linestyle.

A custom linestyle is assumed to be dashed, we do not inspect theonoffseq directly.

See alsoset_linestyle.

lineStyles={'':'_draw_nothing','':'_draw_nothing','-':'_draw_solid','--':'_draw_dashed','-.':'_draw_dash_dot',':':'_draw_dotted','None':'_draw_nothing'}#
markers={'':'nothing','':'nothing','*':'star','+':'plus',',':'pixel','.':'point','1':'tri_down','2':'tri_up','3':'tri_left','4':'tri_right','8':'octagon','<':'triangle_left','>':'triangle_right','D':'diamond','H':'hexagon2','None':'nothing','P':'plus_filled','X':'x_filled','^':'triangle_up','_':'hline','d':'thin_diamond','h':'hexagon1','none':'nothing','o':'circle','p':'pentagon','s':'square','v':'triangle_down','x':'x','|':'vline',0:'tickleft',1:'tickright',10:'caretupbase',11:'caretdownbase',2:'tickup',3:'tickdown',4:'caretleft',5:'caretright',6:'caretup',7:'caretdown',8:'caretleftbase',9:'caretrightbase'}#
propertypickradius#

Return the pick radius used for containment tests.

Seecontains for more details.

recache(always=False)[source]#
recache_always()[source]#
set(*,agg_filter=<UNSET>,alpha=<UNSET>,animated=<UNSET>,antialiased=<UNSET>,clip_box=<UNSET>,clip_on=<UNSET>,clip_path=<UNSET>,color=<UNSET>,dash_capstyle=<UNSET>,dash_joinstyle=<UNSET>,dashes=<UNSET>,data=<UNSET>,drawstyle=<UNSET>,fillstyle=<UNSET>,gapcolor=<UNSET>,gid=<UNSET>,in_layout=<UNSET>,label=<UNSET>,linestyle=<UNSET>,linewidth=<UNSET>,marker=<UNSET>,markeredgecolor=<UNSET>,markeredgewidth=<UNSET>,markerfacecolor=<UNSET>,markerfacecoloralt=<UNSET>,markersize=<UNSET>,markevery=<UNSET>,mouseover=<UNSET>,path_effects=<UNSET>,picker=<UNSET>,pickradius=<UNSET>,rasterized=<UNSET>,sketch_params=<UNSET>,snap=<UNSET>,solid_capstyle=<UNSET>,solid_joinstyle=<UNSET>,transform=<UNSET>,url=<UNSET>,visible=<UNSET>,xdata=<UNSET>,ydata=<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

bool

clip_box

BboxBase or None

clip_on

bool

clip_path

Patch or (Path, Transform) or None

color

color

dash_capstyle

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

dash_joinstyle

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

dashes

sequence of floats (on/off ink in points) or (None, None)

data

(2, N) array or two 1D arrays

drawstyle

{'default', 'steps', 'steps-pre', 'steps-mid', 'steps-post'}, default: 'default'

figure

Figure orSubFigure

fillstyle

{'full', 'left', 'right', 'bottom', 'top', 'none'}

gapcolor

color or None

gid

str

in_layout

bool

label

object

linestyle

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

linewidth

float

marker

marker style string,Path orMarkerStyle

markeredgecolor

color

markeredgewidth

float

markerfacecolor

color

markerfacecoloralt

color

markersize

float

markevery

None or int or (int, int) or slice or list[int] or float or (float, float) or list[bool]

mouseover

bool

path_effects

list ofAbstractPathEffect

picker

float or callable[[Artist, Event], tuple[bool, dict]]

pickradius

float

rasterized

bool

sketch_params

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

snap

bool or None

solid_capstyle

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

solid_joinstyle

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

transform

unknown

url

str

visible

bool

xdata

1D array

ydata

1D array

zorder

float

set_aa(b)[source]#

Alias forset_antialiased.

set_antialiased(b)[source]#

Set whether to use antialiased rendering.

Parameters:
bbool
set_c(color)[source]#

Alias forset_color.

set_color(color)[source]#

Set the color of the line.

Parameters:
colorcolor
set_dash_capstyle(s)[source]#

How to draw the end caps if the line isis_dashed.

The default capstyle isrcParams["lines.dash_capstyle"] (default:<CapStyle.butt:'butt'>).

Parameters:
sCapStyle or {'butt', 'projecting', 'round'}
set_dash_joinstyle(s)[source]#

How to join segments of the line if itis_dashed.

The default joinstyle isrcParams["lines.dash_joinstyle"] (default:<JoinStyle.round:'round'>).

Parameters:
sJoinStyle or {'miter', 'round', 'bevel'}
set_dashes(seq)[source]#

Set the dash sequence.

The dash sequence is a sequence of floats of even length describingthe length of dashes and spaces in points.

For example, (5, 2, 1, 2) describes a sequence of 5 point and 1 pointdashes separated by 2 point spaces.

See alsoset_gapcolor, which allows those spaces to befilled with a color.

Parameters:
seqsequence of floats (on/off ink in points) or (None, None)

Ifseq is empty or(None,None), the linestyle will be setto solid.

set_data(*args)[source]#

Set the x and y data.

Parameters:
*args(2, N) array or two 1D arrays
set_drawstyle(drawstyle)[source]#

Set the drawstyle of the plot.

The drawstyle determines how the points are connected.

Parameters:
drawstyle{'default', 'steps', 'steps-pre', 'steps-mid', 'steps-post'}, default: 'default'

For 'default', the points are connected with straight lines.

The steps variants connect the points with step-like lines,i.e. horizontal lines with vertical steps. They differ in thelocation of the step:

  • 'steps-pre': The step is at the beginning of the line segment,i.e. the line will be at the y-value of point to the right.

  • 'steps-mid': The step is halfway between the points.

  • 'steps-post: The step is at the end of the line segment,i.e. the line will be at the y-value of the point to the left.

  • 'steps' is equal to 'steps-pre' and is maintained forbackward-compatibility.

For examples seeStep Demo.

set_ds(drawstyle)[source]#

Alias forset_drawstyle.

set_fillstyle(fs)[source]#

Set the marker fill style.

Parameters:
fs{'full', 'left', 'right', 'bottom', 'top', 'none'}

Possible values:

  • 'full': Fill the whole marker with themarkerfacecolor.

  • 'left', 'right', 'bottom', 'top': Fill the marker half atthe given side with themarkerfacecolor. The otherhalf of the marker is filled withmarkerfacecoloralt.

  • 'none': No filling.

For examples seeMarker fill styles.

set_gapcolor(gapcolor)[source]#

Set a color to fill the gaps in the dashed line style.

Note

Striped lines are created by drawing two interleaved dashed lines.There can be overlaps between those two, which may result inartifacts when using transparency.

This functionality is experimental and may change.

Parameters:
gapcolorcolor or None

The color with which to fill the gaps. If None, the gaps areunfilled.

set_linestyle(ls)[source]#

Set the linestyle of the line.

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

Possible values:

  • A string:

    linestyle

    description

    '-' or'solid'

    solid line

    '--' or'dashed'

    dashed line

    '-.' or'dashdot'

    dash-dotted line

    ':' or'dotted'

    dotted line

    '' or'none' (discouraged:'None','')

    draw nothing

  • Alternatively a dash tuple of the following form can beprovided:

    (offset,onoffseq)

    whereonoffseq is an even length tuple of on and off inkin points. See alsoset_dashes().

For examples seeLinestyles.

set_linewidth(w)[source]#

Set the line width in points.

Parameters:
wfloat

Line width, in points.

set_ls(ls)[source]#

Alias forset_linestyle.

set_lw(w)[source]#

Alias forset_linewidth.

set_marker(marker)[source]#

Set the line marker.

Parameters:
markermarker style string,Path orMarkerStyle

Seemarkers for full description of possiblearguments.

set_markeredgecolor(ec)[source]#

Set the marker edge color.

Parameters:
eccolor
set_markeredgewidth(ew)[source]#

Set the marker edge width in points.

Parameters:
ewfloat

Marker edge width, in points.

set_markerfacecolor(fc)[source]#

Set the marker face color.

Parameters:
fccolor
set_markerfacecoloralt(fc)[source]#

Set the alternate marker face color.

Parameters:
fccolor
set_markersize(sz)[source]#

Set the marker size in points.

Parameters:
szfloat

Marker size, in points.

set_markevery(every)[source]#

Set the markevery property to subsample the plot when using markers.

e.g., ifevery=5, every 5-th marker will be plotted.

Parameters:
everyNone or int or (int, int) or slice or list[int] or float or (float, float) or list[bool]

Which markers to plot.

  • every=None: every point will be plotted.

  • every=N: every N-th marker will be plotted starting withmarker 0.

  • every=(start,N): every N-th marker, starting at indexstart, will be plotted.

  • every=slice(start,end,N): every N-th marker, starting atindexstart, up to but not including indexend, will beplotted.

  • every=[i,j,m,...]: only markers at the given indiceswill be plotted.

  • every=[True,False,True,...]: only positions that are Truewill be plotted. The list must have the same length as the datapoints.

  • every=0.1, (i.e. a float): markers will be spaced atapproximately equal visual distances along the line; the distancealong the line between markers is determined by multiplying thedisplay-coordinate distance of the Axes bounding-box diagonalby the value ofevery.

  • every=(0.5,0.1) (i.e. a length-2 tuple of float): similartoevery=0.1 but the first marker will be offset along theline by 0.5 multiplied by thedisplay-coordinate-diagonal-distance along the line.

For examples seeMarkevery Demo.

Notes

Settingmarkevery will still only draw markers at actual data points.While the float argument form aims for uniform visual spacing, it hasto coerce from the ideal spacing to the nearest available data point.Depending on the number and distribution of data points, the resultmay still not look evenly spaced.

When using a start offset to specify the first marker, the offset willbe from the first data point which may be different from the firstthe visible data point if the plot is zoomed in.

If zooming in on a plot when using float arguments then the actualdata points that have markers will change because the distance betweenmarkers is always determined from the display-coordinatesaxes-bounding-box-diagonal regardless of the actual axes data limits.

set_mec(ec)[source]#

Alias forset_markeredgecolor.

set_mew(ew)[source]#

Alias forset_markeredgewidth.

set_mfc(fc)[source]#

Alias forset_markerfacecolor.

set_mfcalt(fc)[source]#

Alias forset_markerfacecoloralt.

set_ms(sz)[source]#

Alias forset_markersize.

set_picker(p)[source]#

Set the event picker details for the line.

Parameters:
pfloat or callable[[Artist, Event], tuple[bool, dict]]

If a float, it is used as the pick radius in points.

set_pickradius(pickradius)[source]#

Set the pick radius used for containment tests.

Seecontains for more details.

Parameters:
pickradiusfloat

Pick radius, in points.

set_solid_capstyle(s)[source]#

How to draw the end caps if the line is solid (notis_dashed)

The default capstyle isrcParams["lines.solid_capstyle"] (default:<CapStyle.projecting:'projecting'>).

Parameters:
sCapStyle or {'butt', 'projecting', 'round'}
set_solid_joinstyle(s)[source]#

How to join segments if the line is solid (notis_dashed).

The default joinstyle isrcParams["lines.solid_joinstyle"] (default:<JoinStyle.round:'round'>).

Parameters:
sJoinStyle or {'miter', 'round', 'bevel'}
set_transform(t)[source]#

Set the artist transform.

Parameters:
tTransform
set_xdata(x)[source]#

Set the data array for x.

Parameters:
x1D array
set_ydata(y)[source]#

Set the data array for y.

Parameters:
y1D array
update_from(other)[source]#

Copy properties fromother to self.

zorder=2#

Examples usingmatplotlib.lines.Line2D#

Decay

Decay

The double pendulum problem

The double pendulum problem

Multiple Axes animation

Multiple Axes animation

Animated line plot

Animated line plot

Oscilloscope

Oscilloscope

Matplotlib unchained

Matplotlib unchained

Parasite Simple

Parasite Simple

Parasite Axes demo

Parasite Axes demo

Parasite axis demo

Parasite axis demo

Cross-hair cursor

Cross-hair cursor

Data browser

Data browser

Legend picking

Legend picking

Looking glass

Looking glass

Pick event demo

Pick event demo

Pick event demo 2

Pick event demo 2

Polygon editor

Polygon editor

Dashed line style configuration

Dashed line style configuration

Stem plot

Stem plot

Anchored Artists

Anchored Artists

Add lines directly to a figure

Add lines directly to a figure

Patheffect Demo

Patheffect Demo

Set and get properties

Set and get properties

Apply SVG filter to a line

Apply SVG filter to a line

Reference for Matplotlib artists

Reference for Matplotlib artists

PathPatch object

PathPatch object

Stock prices over 32 years

Stock prices over 32 years

SkewT-logP diagram: using transforms and custom projections

SkewT-logP diagram: using transforms and custom projections

Multiple y-axis with Spines

Multiple y-axis with Spines

Boxplots

Boxplots

Figure labels: suptitle, supxlabel, supylabel

Figure labels: suptitle, supxlabel, supylabel

Scale invariant angle label

Scale invariant angle label

Annotating a plot

Annotating a plot

Annotate plots

Annotate plots

Annotate polar plots

Annotate polar plots

Compose custom legends

Compose custom legends

Annotation arrow style reference

Annotation arrow style reference

Legend Demo

Legend Demo

Artist within an artist

Artist within an artist

Custom tick formatter for time series

Custom tick formatter for time series

Artist tests

Artist tests

Annotated cursor

Annotated cursor

Buttons

Buttons

Check buttons

Check buttons

Radio Buttons

Radio Buttons

Image scaling using a RangeSlider

Image scaling using a RangeSlider

Slider

Slider

Snap sliders to discrete values

Snap sliders to discrete values

Span Selector

Span Selector

Textbox

Textbox

Artist tutorial

Artist tutorial

Pyplot tutorial

Pyplot tutorial

Animations using Matplotlib

Animations using Matplotlib

Faster rendering by using blitting

Faster rendering by using blitting

Transformations Tutorial

Transformations Tutorial

Legend guide

Legend guide

Quick start guide

Quick start guide

Annotations

Annotations
On this page