Movatterモバイル変換


[0]ホーム

URL:


You are reading an old version of the documentation (v2.0.0). For the latest version seehttps://matplotlib.org/stable/api/lines_api.html
matplotlib

Navigation


Travis-CI:

Table Of Contents

Related Topics

This Page

Quick search

lines

matplotlib.lines

This module contains all the 2D line class which can draw with avariety of line styles, markers and colors.

classmatplotlib.lines.Line2D(xdata,ydata,linewidth=None,linestyle=None,color=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)

Bases:matplotlib.artist.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 withxandy data in sequencesxdata,ydata.

The kwargs areLine2D properties:

PropertyDescription
agg_filterunknown
alphafloat (0.0 transparent through 1.0 opaque)
animated[True | False]
antialiased or aa[True | False]
axesanAxes instance
clip_boxamatplotlib.transforms.Bbox instance
clip_on[True | False]
clip_path[ (Path,Transform) |Patch | None ]
color or cany matplotlib color
containsa callable function
dash_capstyle[‘butt’ | ‘round’ | ‘projecting’]
dash_joinstyle[‘miter’ | ‘round’ | ‘bevel’]
dashessequence of on/off ink in points
drawstyle[‘default’ | ‘steps’ | ‘steps-pre’ | ‘steps-mid’ | ‘steps-post’]
figureamatplotlib.figure.Figure instance
fillstyle[‘full’ | ‘left’ | ‘right’ | ‘bottom’ | ‘top’ | ‘none’]
gidan id string
labelstring or anything printable with ‘%s’ conversion.
linestyle or ls[‘solid’ | ‘dashed’, ‘dashdot’, ‘dotted’ | (offset, on-off-dash-seq) |'-' |'--' |'-.' |':' |'None' |'' |'']
linewidth or lwfloat value in points
markerAvalidmarkerstyle
markeredgecolor or mecany matplotlib color
markeredgewidth or mewfloat value in points
markerfacecolor or mfcany matplotlib color
markerfacecoloralt or mfcaltany matplotlib color
markersize or msfloat
markevery[None | int | length-2 tuple of int | slice | list/array of int | float | length-2 tuple of float]
path_effectsunknown
pickerfloat distance in points or callable pick functionfn(artist,event)
pickradiusfloat distance in points
rasterized[True | False | None]
sketch_paramsunknown
snapunknown
solid_capstyle[‘butt’ | ‘round’ | ‘projecting’]
solid_joinstyle[‘miter’ | ‘round’ | ‘bevel’]
transformamatplotlib.transforms.Transform instance
urla url string
visible[True | False]
xdata1D array
ydata1D array
zorderany number

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

axes

TheAxes instance the artistresides in, orNone.

contains(mouseevent)

Test whether the mouse event occurred on the line. The pickradius determines the precision of the location test (usuallywithin five points of the value). Useget_pickradius() orset_pickradius() to view ormodify it.

ReturnsTrue if any values are within the radius along with{'ind':pointlist}, wherepointlist is the set of pointswithin the radius.

TODO: sort returned indices by distance

draw(artist,renderer,*args,**kwargs)

draw the Line withrenderer unless visibility is False

drawStyleKeys = ['default', 'steps-mid', 'steps-pre', 'steps-post', 'steps']
drawStyles = {'default': '_draw_lines', 'steps-mid': '_draw_steps_mid', 'steps-pre': '_draw_steps_pre', 'steps-post': '_draw_steps_post', 'steps': '_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()

alias for get_antialiased

get_antialiased()
get_c()

alias for get_color

get_color()
get_dash_capstyle()

Get the cap style for dashed linestyles

get_dash_joinstyle()

Get the join style for dashed linestyles

get_data(orig=True)

Return the xdata, ydata.

Iforig isTrue, return the original data.

get_drawstyle()
get_fillstyle()

return the marker fillstyle

get_linestyle()
get_linewidth()
get_ls()

alias for get_linestyle

get_lw()

alias for get_linewidth

get_marker()
get_markeredgecolor()
get_markeredgewidth()
get_markerfacecolor()
get_markerfacecoloralt()
get_markersize()
get_markevery()

return the markevery setting

get_mec()

alias for get_markeredgecolor

get_mew()

alias for get_markeredgewidth

get_mfc()

alias for get_markerfacecolor

get_mfcalt(alt=False)

alias for get_markerfacecoloralt

get_ms()

alias for get_markersize

get_path()

Return thePath object associatedwith this line.

get_pickradius()

return the pick radius used for containment tests

get_solid_capstyle()

Get the cap style for solid linestyles

get_solid_joinstyle()

Get the join style for solid linestyles

get_window_extent(renderer)
get_xdata(orig=True)

Return the xdata.

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

get_xydata()

Return thexy data as a Nx2 numpy array.

get_ydata(orig=True)

Return the ydata.

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

is_dashed()

return True if line is dashstyle

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

alias for set_antialiased

set_antialiased(b)

True if line should be drawin with antialiased rendering

ACCEPTS: [True | False]

set_c(val)

alias for set_color

set_color(color)

Set the color of the line

ACCEPTS: any matplotlib color

set_dash_capstyle(s)

Set the cap style for dashed linestyles

ACCEPTS: [‘butt’ | ‘round’ | ‘projecting’]

set_dash_joinstyle(s)

Set the join style for dashed linestylesACCEPTS: [‘miter’ | ‘round’ | ‘bevel’]

set_dashes(seq)

Set the dash sequence, sequence of dashes with on off ink inpoints. If seq is empty or if seq = (None, None), thelinestyle will be set to solid.

ACCEPTS: sequence of on/off ink in points

set_data(*args)

Set the x and y data

ACCEPTS: 2D array (rows are x, y) or two 1D arrays

set_drawstyle(drawstyle)

Set the drawstyle of the plot

‘default’ connects the points with lines. The steps variantsproduce step-plots. ‘steps’ is equivalent to ‘steps-pre’ andis maintained for backward-compatibility.

ACCEPTS: [‘default’ | ‘steps’ | ‘steps-pre’ | ‘steps-mid’ |
‘steps-post’]
set_fillstyle(fs)

Set the marker fill style; ‘full’ means fill the whole marker.‘none’ means no filling; other options are for half-filled markers.

ACCEPTS: [‘full’ | ‘left’ | ‘right’ | ‘bottom’ | ‘top’ | ‘none’]

set_linestyle(ls)

Set the linestyle of the line (also accepts drawstyles,e.g.,'steps--')

linestyledescription
'-' or'solid'solid line
'--' or'dashed'dashed line
'-.' or'dashdot'dash-dotted line
':' or'dotted'dotted line
'None'draw nothing
''draw nothing
''draw nothing

‘steps’ is equivalent to ‘steps-pre’ and is maintained forbackward-compatibility.

Alternatively a dash tuple of the following form can be provided:

(offset,onoffseq),

whereonoffseq is an even length tuple of on and off inkin points.

ACCEPTS: [‘solid’ | ‘dashed’, ‘dashdot’, ‘dotted’ |
(offset, on-off-dash-seq) |'-' |'--' |'-.' |':' |'None' |'' |'']

See also

set_drawstyle()
To set the drawing style (stepping) of the plot.
Parameters:

ls : {'-','--','-.',':'} and more see description

The line style.

set_linewidth(w)

Set the line width in points

ACCEPTS: float value in points

set_ls(val)

alias for set_linestyle

set_lw(val)

alias for set_linewidth

set_marker(marker)

Set the line marker

ACCEPTS:Avalidmarkerstyle

Parameters:

marker: marker style

Seemarkers for full description of possibleargument

set_markeredgecolor(ec)

Set the marker edge color

ACCEPTS: any matplotlib color

set_markeredgewidth(ew)

Set the marker edge width in points

ACCEPTS: float value in points

set_markerfacecolor(fc)

Set the marker face color.

ACCEPTS: any matplotlib color

set_markerfacecoloralt(fc)

Set the alternate marker face color.

ACCEPTS: any matplotlib color

set_markersize(sz)

Set the marker size in points

ACCEPTS: float

set_markevery(every)

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

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

ACCEPTS: [None | int | length-2 tuple of int | slice |list/array of int | float | length-2 tuple of float]

Parameters:

every: None | int | length-2 tuple of int | slice | list/array of int |

float | length-2 tuple of float

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 pointstart, will be plotted.
  • every=slice(start, end, N), every N-th marker, starting atpoint start, upto but not including point end, will be plotted.
  • every=[i, j, m, n], only markers at points i, j, m, and nwill be plotted.
  • every=0.1, (i.e. a float) then markers will be spaced atapproximately equal 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 of every.
  • every=(0.5, 0.1) (i.e. a length-2 tuple of float), thesame functionality as every=0.1 is exhibited but the firstmarker will be 0.5 multiplied by thedisplay-cordinate-diagonal-distance along the line.

Notes

Setting the markevery property will only show markers at actual datapoints. When using float arguments to set the markevery propertyon irregularly spaced data, the markers will likely not appear evenlyspaced because the actual data points do not coincide with thetheoretical spacing between markers.

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(val)

alias for set_markeredgecolor

set_mew(val)

alias for set_markeredgewidth

set_mfc(val)

alias for set_markerfacecolor

set_mfcalt(val)

alias for set_markerfacecoloralt

set_ms(val)

alias for set_markersize

set_picker(p)

Sets the event picker details for the line.

ACCEPTS: float distance in points or callable pick functionfn(artist,event)

set_pickradius(d)

Sets the pick radius used for containment tests

ACCEPTS: float distance in points

set_solid_capstyle(s)

Set the cap style for solid linestyles

ACCEPTS: [‘butt’ | ‘round’ | ‘projecting’]

set_solid_joinstyle(s)

Set the join style for solid linestylesACCEPTS: [‘miter’ | ‘round’ | ‘bevel’]

set_transform(t)

set the Transformation instance used by this artist

ACCEPTS: amatplotlib.transforms.Transform instance

set_xdata(x)

Set the data np.array for x

ACCEPTS: 1D array

set_ydata(y)

Set the data np.array for y

ACCEPTS: 1D array

update_from(other)

copy properties from other to self

validCap = ('butt', 'round', 'projecting')
validJoin = ('miter', 'round', 'bevel')
zorder = 2
classmatplotlib.lines.VertexSelector(line)

Bases:object

Manage the callbacks to maintain a list of selected vertices formatplotlib.lines.Line2D. Derived classes should overrideprocess_selected() to dosomething with the picks.

Here is an example which highlights the selected verts with redcircles:

importnumpyasnpimportmatplotlib.pyplotaspltimportmatplotlib.linesaslinesclassHighlightSelected(lines.VertexSelector):def__init__(self,line,fmt='ro',**kwargs):lines.VertexSelector.__init__(self,line)self.markers,=self.axes.plot([],[],fmt,**kwargs)defprocess_selected(self,ind,xs,ys):self.markers.set_data(xs,ys)self.canvas.draw()fig=plt.figure()ax=fig.add_subplot(111)x,y=np.random.rand(2,30)line,=ax.plot(x,y,'bs-',picker=5)selector=HighlightSelected(line)plt.show()

Initialize the class with amatplotlib.lines.Line2Dinstance. The line should already be added to somematplotlib.axes.Axes instance and should have thepicker property set.

onpick(event)

When the line is picked, update the set of selected indicies.

process_selected(ind,xs,ys)

Default “do nothing” implementation of theprocess_selected() method.

ind are the indices of the selected vertices.xs andysare the coordinates of the selected vertices.

matplotlib.lines.segment_hits(cx,cy,x,y,radius)

Determine if any line segments are within radius of apoint. Returns the list of line segments that are within thatradius.

© Copyright 2002 - 2012 John Hunter, Darren Dale, Eric Firing, Michael Droettboom and the Matplotlib development team; 2012 - 2016 The Matplotlib development team. Last updated on Feb 20, 2017. Created usingSphinx 1.5.2.

[8]ページ先頭

©2009-2025 Movatter.jp