This module contains all the 2D line class which can draw with a variety of line styles, markers and colors.
Bases: matplotlib.artist.Artist
A line - the line can have both a solid linestyle connecting all the vertices, and a marker at each vertex. Additionally, the drawing of the solid line is influenced by the drawstyle, e.g., one can create “stepped” lines in various styles.
Create a Line2D instance with x and y data in sequences xdata, ydata.
The kwargs are Line2D properties:
Property Description agg_filter unknown alpha float (0.0 transparent through 1.0 opaque) animated [True | False] antialiased or aa [True | False] axes an Axes instance clip_box a matplotlib.transforms.Bbox instance clip_on [True | False] clip_path [ (Path, Transform) | Patch | None ] color or c any matplotlib color contains a callable function dash_capstyle [‘butt’ | ‘round’ | ‘projecting’] dash_joinstyle [‘miter’ | ‘round’ | ‘bevel’] dashes sequence of on/off ink in points drawstyle [‘default’ | ‘steps’ | ‘steps-pre’ | ‘steps-mid’ | ‘steps-post’] figure a matplotlib.figure.Figure instance fillstyle [‘full’ | ‘left’ | ‘right’ | ‘bottom’ | ‘top’ | ‘none’] gid an id string label string or anything printable with ‘%s’ conversion. linestyle or ls ['-' | '--' | '-.' | ':' | 'None' | ' ' | ''] linewidth or lw float value in points lod [True | False] marker A valid marker style markeredgecolor or mec any matplotlib color markeredgewidth or mew float value in points markerfacecolor or mfc any matplotlib color markerfacecoloralt or mfcalt any matplotlib color markersize or ms float markevery [None | int | length-2 tuple of int | slice | list/array of int | float | length-2 tuple of float] path_effects unknown picker float distance in points or callable pick function fn(artist, event) pickradius float distance in points rasterized [True | False | None] sketch_params unknown snap unknown solid_capstyle [‘butt’ | ‘round’ | ‘projecting’] solid_joinstyle [‘miter’ | ‘round’ | ‘bevel’] transform a matplotlib.transforms.Transform instance url a url string visible [True | False] xdata 1D array ydata 1D array zorder any number
See set_linestyle() for a decription of the line styles, set_marker() for a description of the markers, and set_drawstyle() for a description of the draw styles.
Test whether the mouse event occurred on the line. The pick radius determines the precision of the location test (usually within five points of the value). Use get_pickradius() or set_pickradius() to view or modify it.
Returns True if any values are within the radius along with {'ind': pointlist}, where pointlist is the set of points within the radius.
TODO: sort returned indices by distance
draw the Line with renderer unless visibility is False
alias for get_antialiased
alias for get_color
Get the cap style for dashed linestyles
Get the join style for dashed linestyles
Return the xdata, ydata.
If orig is True, return the original data.
return the marker fillstyle
alias for get_linestyle
alias for get_linewidth
return the markevery setting
alias for get_markeredgecolor
alias for get_markeredgewidth
alias for get_markerfacecolor
alias for get_markerfacecoloralt
alias for get_markersize
return the pick radius used for containment tests
Get the cap style for solid linestyles
Get the join style for solid linestyles
Return the xdata.
If orig is True, return the original data, else the processed data.
Return the xy data as a Nx2 numpy array.
Return the ydata.
If orig is True, return the original data, else the processed data.
return True if line is dashstyle
alias for set_antialiased
True if line should be drawin with antialiased rendering
ACCEPTS: [True | False]
alias for set_color
Set the color of the line
ACCEPTS: any matplotlib color
Set the cap style for dashed linestyles
ACCEPTS: [‘butt’ | ‘round’ | ‘projecting’]
Set the join style for dashed linestyles ACCEPTS: [‘miter’ | ‘round’ | ‘bevel’]
Set the dash sequence, sequence of dashes with on off ink in points. If seq is empty or if seq = (None, None), the linestyle will be set to solid.
ACCEPTS: sequence of on/off ink in points
Set the x and y data
ACCEPTS: 2D array (rows are x, y) or two 1D arrays
Set the drawstyle of the plot
‘default’ connects the points with lines. The steps variants produce step-plots. ‘steps’ is equivalent to ‘steps-pre’ and is maintained for backward-compatibility.
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 the linestyle of the line (also accepts drawstyles)
linestyle | description |
---|---|
'-' | solid |
'--' | dashed |
'-.' | dash_dot |
':' | dotted |
'None' | draw nothing |
' ' | draw nothing |
'' | draw nothing |
‘steps’ is equivalent to ‘steps-pre’ and is maintained for backward-compatibility.
See also
and any drawstyle in combination with a linestyle, e.g., 'steps--'.
Set the line width in points
ACCEPTS: float value in points
alias for set_linestyle
alias for set_linewidth
Set the line marker
ACCEPTS: A valid marker style
Parameters: | marker: marker style
|
---|
Set the marker edge color
ACCEPTS: any matplotlib color
Set the marker edge width in points
ACCEPTS: float value in points
Set the marker face color.
ACCEPTS: any matplotlib color
Set the alternate marker face color.
ACCEPTS: any matplotlib color
Set the marker size in points
ACCEPTS: float
Set the markevery property to subsample the plot when using markers.
e.g., if every=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
|
---|
Notes
Setting the markevery property will only show markers at actual data points. When using float arguments to set the markevery property on irregularly spaced data, the markers will likely not appear evenly spaced because the actual data points do not coincide with the theoretical spacing between markers.
When using a start offset to specify the first marker, the offset will be from the first data point which may be different from the first the visible data point if the plot is zoomed in.
If zooming in on a plot when using float arguments then the actual data points that have markers will change because the distance between markers is always determined from the display-coordinates axes-bounding-box-diagonal regardless of the actual axes data limits.
alias for set_markeredgecolor
alias for set_markeredgewidth
alias for set_markerfacecolor
alias for set_markerfacecoloralt
alias for set_markersize
Sets the event picker details for the line.
ACCEPTS: float distance in points or callable pick function fn(artist, event)
Sets the pick radius used for containment tests
ACCEPTS: float distance in points
Set the cap style for solid linestyles
ACCEPTS: [‘butt’ | ‘round’ | ‘projecting’]
Set the join style for solid linestyles ACCEPTS: [‘miter’ | ‘round’ | ‘bevel’]
set the Transformation instance used by this artist
ACCEPTS: a matplotlib.transforms.Transform instance
Set the data np.array for x
ACCEPTS: 1D array
Set the data np.array for y
ACCEPTS: 1D array
copy properties from other to self
Bases: object
Manage the callbacks to maintain a list of selected vertices for matplotlib.lines.Line2D. Derived classes should override process_selected() to do something with the picks.
Here is an example which highlights the selected verts with red circles:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.lines as lines
class HighlightSelected(lines.VertexSelector):
def __init__(self, line, fmt='ro', **kwargs):
lines.VertexSelector.__init__(self, line)
self.markers, = self.axes.plot([], [], fmt, **kwargs)
def process_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 a matplotlib.lines.Line2D instance. The line should already be added to some matplotlib.axes.Axes instance and should have the picker property set.
When the line is picked, update the set of selected indicies.
Default “do nothing” implementation of the process_selected() method.
ind are the indices of the selected vertices. xs and ys are the coordinates of the selected vertices.
Determine if any line segments are within radius of a point. Returns the list of line segments that are within that radius.