On this page
matplotlib.pyplot.errorbar
matplotlib.pyplot.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 errorbar sizes. By default, this draws the data markers/lines as well the errorbars. Use fmt='none' to draw errorbars without any data markers.
Parameters: -
x, yscalar or array-like -
The data positions.
-
xerr, yerrscalar 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 row contains the lower errors, the second row contains the upper errors.
- None: No errorbar.
Note that all error arrays should have positive values.
See Different ways of specifying error bars for an example on the usage of
xerrandyerr. -
fmtstr, optional, default: '' -
The format for the data points / data lines. See
plotfor details.Use 'none' (case insensitive) to plot errorbars without any data markers.
-
ecolorcolor, optional, default: None -
The color of the errorbar lines. If None, use the color of the line connecting the markers.
-
elinewidthscalar, optional, default: None -
The linewidth of the errorbar lines. If None, the linewidth of the current style is used.
-
capsizescalar, optional, default: None -
The length of the error bar caps in points. If None, it will take the value from
rcParams["errorbar.capsize"](default: 0.0). -
capthickscalar, optional, default: None -
An alias to the keyword argument markeredgewidth (a.k.a. mew). This setting is a more sensible name for the property that controls the thickness of the error bar cap in points. For backwards compatibility, if mew or markeredgewidth are given, then they will over-ride capthick. This may change in future releases.
-
barsabovebool, optional, default: False -
If True, will plot the errorbars above the plot symbols. Default is below.
-
lolims, uplims, xlolims, xuplimsbool, optional, default: False -
These arguments can be used to indicate that a value gives only upper/lower limits. In that case a caret symbol is used to indicate this. lims-arguments may be of the same type as xerr and yerr. To use limits with inverted axes,
set_xlim()orset_ylim()must be called beforeerrorbar(). -
erroreveryint or (int, int), optional, default: 1 -
draws error bars on a subset of the data. errorevery =N draws error 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-axis values.
Returns: -
containerErrorbarContainer -
The container contains:
- plotline:
Line2Dinstance of x, y plot markers and/or line. - caplines: A tuple of
Line2Dinstances of the error bar caps. - barlinecols: A tuple of
LineCollectionwith the horizontal and vertical error ranges.
- plotline:
Other Parameters: - **kwargs
-
All other keyword arguments are passed on to the plot command for the markers. For example, this code makes big red squares with thick green edges:
x, y, yerr = rand(3, 10) errorbar(x, y, yerr, marker='s', mfc='red', mec='green', ms=20, mew=4)where mfc, mec, ms and mew are aliases for the longer property names, markerfacecolor, markeredgecolor, markersize and markeredgewidth.
Valid kwargs for the marker properties are
Lines2Dproperties:Property Description agg_filtera filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array alphafloat or None animatedbool antialiasedor aabool clip_boxBboxclip_onbool clip_pathPatch or (Path, Transform) or None coloror ccolor containscallable dash_capstyle{'butt', 'round', 'projecting'} dash_joinstyle{'miter', 'round', 'bevel'} dashessequence of floats (on/off ink in points) or (None, None) data(2, N) array or two 1D arrays drawstyleor ds{'default', 'steps', 'steps-pre', 'steps-mid', 'steps-post'}, default: 'default' figureFigurefillstyle{'full', 'left', 'right', 'bottom', 'top', 'none'} gidstr in_layoutbool labelobject linestyleor ls{'-', '--', '-.', ':', '', (offset, on-off-seq), ...} linewidthor lwfloat markermarker style markeredgecoloror meccolor markeredgewidthor mewfloat markerfacecoloror mfccolor markerfacecoloraltor mfcaltcolor markersizeor msfloat markeveryNone or int or (int, int) or slice or List[int] or float or (float, float) path_effectsAbstractPathEffectpickerfloat or callable[[Artist, Event], Tuple[bool, dict]] pickradiusfloat rasterizedbool or None sketch_params(scale: float, length: float, randomness: float) snapbool or None solid_capstyle{'butt', 'round', 'projecting'} solid_joinstyle{'miter', 'round', 'bevel'} transformmatplotlib.transforms.Transformurlstr visiblebool xdata1D array ydata1D array zorderfloat
Notes
Note
In addition to the above described arguments, this function can take a data keyword argument. If such a data argument is given, the following arguments are replaced by data[<arg>]:
- All arguments with the following names: 'x', 'xerr', 'y', 'yerr'.
Objects passed as data must support item access (
data[<arg>]) and membership test (<arg> in data). -
Examples using matplotlib.pyplot.errorbar
© 2012–2018 Matplotlib Development Team. All rights reserved.
Licensed under the Matplotlib License Agreement.
https://matplotlib.org/3.2.2/api/_as_gen/matplotlib.pyplot.errorbar.html