matplotlib.axes.Axes.errorbar#
- Axes.errorbar(x,y,yerr=None,xerr=None,fmt='',*,ecolor=None,elinewidth=None,capsize=None,barsabove=False,lolims=False,uplims=False,xlolims=False,xuplims=False,errorevery=1,capthick=None,data=None,**kwargs)[source]#
Plot y versus x as lines and/or markers with attached errorbars.
x,y define the data locations,xerr,yerr define the errorbarsizes. By default, this draws the data markers/lines as well as theerrorbars. Use fmt='none' to draw errorbars without any data markers.
Added in version 3.7:Caps and error lines are drawn in polar coordinates on polar plots.
- Parameters:
- x, yfloat or array-like
The data positions.
- xerr, yerrfloat or array-like, shape(N,) or shape(2, N), optional
The errorbar sizes:
scalar: Symmetric +/- values for all data points.
shape(N,): Symmetric +/-values for each data point.
shape(2, N): Separate - and + values for each bar. First rowcontains the lower errors, the second row contains the uppererrors.
None: No errorbar.
All values must be >= 0.
SeeDifferent ways of specifying error barsfor an example on the usage of
xerr
andyerr
.- fmtstr, default: ''
The format for the data points / data lines. See
plot
fordetails.Use 'none' (case-insensitive) to plot errorbars without any datamarkers.
- ecolorcolor, default: None
The color of the errorbar lines. If None, use the color of theline connecting the markers.
- elinewidthfloat, default: None
The linewidth of the errorbar lines. If None, the linewidth ofthe current style is used.
- capsizefloat, default:
rcParams["errorbar.capsize"]
(default:0.0
) The length of the error bar caps in points.
- capthickfloat, default: None
An alias to the keyword argumentmarkeredgewidth (a.k.a.mew).This setting is a more sensible name for the property thatcontrols the thickness of the error bar cap in points. Forbackwards compatibility, ifmew ormarkeredgewidth are given,then they will over-ridecapthick. This may change in futurereleases.
- barsabovebool, default: False
If True, will plot the errorbars above the plotsymbols. Default is below.
- lolims, uplims, xlolims, xuplimsbool or array-like, default: False
These arguments can be used to indicate that a value gives onlyupper/lower limits. In that case a caret symbol is used toindicate this.lims-arguments may be scalars, or array-likes ofthe same length asxerr andyerr. To use limits with invertedaxes,
set_xlim
orset_ylim
must be called beforeerrorbar()
. Note the tricky parameter names: setting e.g.lolims to True means that the y-value is alower limit of theTrue value, so, only anupward-pointing arrow will be drawn!- erroreveryint or (int, int), default: 1
draws error bars on a subset of the data.errorevery =N drawserror bars on the points (x[::N], y[::N]).errorevery =(start, N) draws error bars on the points(x[start::N], y[start::N]). e.g. errorevery=(6, 3)adds error bars to the data at (x[6], x[9], x[12], x[15], ...).Used to avoid overlapping error bars when two series share x-axisvalues.
- Returns:
ErrorbarContainer
The container contains:
data_line : A
Line2D
instance of x, y plot markersand/or line.caplines : A tuple of
Line2D
instances of the errorbar caps.barlinecols : A tuple of
LineCollection
with the horizontal andvertical error ranges.
- Other Parameters:
- dataindexable object, optional
If given, the following parameters also accept a string
s
, which isinterpreted asdata[s]
ifs
is a key indata
:x,y,xerr,yerr
- **kwargs
All other keyword arguments are passed on to the
plot
calldrawing the markers. For example, this code makes big red squareswith thick green edges:x,y,yerr=rand(3,10)errorbar(x,y,yerr,marker='s',mfc='red',mec='green',ms=20,mew=4)
wheremfc,mec,ms andmew are aliases for the longerproperty names,markerfacecolor,markeredgecolor,markersizeandmarkeredgewidth.
Valid kwargs for the marker properties are:
dashes
dash_capstyle
dash_joinstyle
drawstyle
fillstyle
linestyle
marker
markeredgecolor
markeredgewidth
markerfacecolor
markerfacecoloralt
markersize
markevery
solid_capstyle
solid_joinstyle
Refer to the corresponding
Line2D
property for more details:Property
Description
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
float or None
bool
bool
BboxBase
or Nonebool
Patch or (Path, Transform) or None
CapStyle
or {'butt', 'projecting', 'round'}JoinStyle
or {'miter', 'round', 'bevel'}sequence of floats (on/off ink in points) or (None, None)
(2, N) array or two 1D arrays
{'default', 'steps', 'steps-pre', 'steps-mid', 'steps-post'}, default: 'default'
{'full', 'left', 'right', 'bottom', 'top', 'none'}
color or None
str
bool
object
{'-', '--', '-.', ':', '', (offset, on-off-seq), ...}
float
marker style string,
Path
orMarkerStyle
float
markersize
orms
float
None or int or (int, int) or slice or list[int] or float or (float, float) or list[bool]
bool
list of
AbstractPathEffect
float or callable[[Artist, Event], tuple[bool, dict]]
float
bool
(scale: float, length: float, randomness: float)
bool or None
CapStyle
or {'butt', 'projecting', 'round'}JoinStyle
or {'miter', 'round', 'bevel'}unknown
str
bool
1D array
1D array
float
Examples usingmatplotlib.axes.Axes.errorbar
#

Create boxes from error bars using PatchCollection