matplotlib
Fork me on GitHub


Travis-CI:

This Page

matplotlib.axes.Axes.bar

Axes.bar(*args, data=None, **kwargs)

Make a bar plot.

Call signatures:

bar(x, height, *, align='center', **kwargs)
bar(x, height, width, *, align='center', **kwargs)
bar(x, height, width, bottom, *, align='center', **kwargs)

Make a bar plot with rectangles bounded by

(left, right, bottom and top edges) by default. x, height, width, and bottom can be either scalars or sequences.

The align and orientation kwargs control the interpretation of x and bottom

The align keyword-only argument controls if x is interpreted as the center or the left edge of the rectangle.

Parameters:

x : sequence of scalars

the x coordinates of the bars.

align controls if x is the bar center (default) or left edge.

height : scalar or sequence of scalars

the height(s) of the bars

width : scalar or array-like, optional

the width(s) of the bars default: 0.8

bottom : scalar or array-like, optional

the y coordinate(s) of the bars default: None

align : {‘center’, ‘edge’}, optional, default: ‘center’

If ‘center’, interpret the x argument as the coordinates of the centers of the bars. If ‘edge’, aligns bars by their left edges

To align the bars on the right edge pass a negative width and align='edge'

Returns:

bars : matplotlib.container.BarContainer

Container with all of the bars + errorbars

Other Parameters:
 

color : scalar or array-like, optional

the colors of the bar faces

edgecolor : scalar or array-like, optional

the colors of the bar edges

linewidth : scalar or array-like, optional

width of bar edge(s). If None, use default linewidth; If 0, don’t draw edges. default: None

tick_label : string or array-like, optional

the tick labels of the bars default: None

xerr : scalar or array-like, optional

if not None, will be used to generate errorbar(s) on the bar chart default: None

yerr : scalar or array-like, optional

if not None, will be used to generate errorbar(s) on the bar chart default: None

ecolor : scalar or array-like, optional

specifies the color of errorbar(s) default: None

capsize : scalar, optional

determines the length in points of the error bar caps default: None, which will take the value from the errorbar.capsize rcParam.

error_kw : dict, optional

dictionary of kwargs to be passed to errorbar method. ecolor and capsize may be specified here rather than as independent kwargs.

log : boolean, optional

If true, sets the axis to be log scale. default: False

orientation : {‘vertical’, ‘horizontal’}, optional

This is for internal use, please do not directly use this, call barh instead.

The orientation of the bars.

See also

barh
Plot a horizontal bar plot.

Notes

The optional arguments color, edgecolor, linewidth, xerr, and yerr can be either scalars or sequences of length equal to the number of bars. This enables you to use bar as the basis for stacked bar charts, or candlestick plots. Detail: xerr and yerr are passed directly to errorbar(), so they can also have shape 2xN for independent specification of lower and upper errors.

Other optional kwargs:

Property Description
agg_filter unknown
alpha float or None
animated [True | False]
antialiased or aa [True | False] or None for default
capstyle [‘butt’ | ‘round’ | ‘projecting’]
clip_box a matplotlib.transforms.Bbox instance
clip_on [True | False]
clip_path [ (Path, Transform) | Patch | None ]
color matplotlib color spec
contains a callable function
edgecolor or ec mpl color spec, None, ‘none’, or ‘auto’
facecolor or fc mpl color spec, or None for default, or ‘none’ for no color
figure a matplotlib.figure.Figure instance
fill [True | False]
gid an id string
hatch [‘/’ | ‘' | ‘|’ | ‘-‘ | ‘+’ | ‘x’ | ‘o’ | ‘O’ | ‘.’ | ‘*’]
joinstyle [‘miter’ | ‘round’ | ‘bevel’]
label string or anything printable with ‘%s’ conversion.
linestyle or ls [‘solid’ | ‘dashed’, ‘dashdot’, ‘dotted’ | (offset, on-off-dash-seq) | '-' | '--' | '-.' | ':' | 'None' | ' ' | '']
linewidth or lw float or None for default
path_effects unknown
picker [None|float|boolean|callable]
rasterized [True | False | None]
sketch_params unknown
snap unknown
transform Transform instance
url a url string
visible [True | False]
zorder any number

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: ‘bottom’, ‘color’, ‘ecolor’, ‘edgecolor’, ‘height’, ‘left’, ‘linewidth’, ‘tick_label’, ‘width’, ‘x’, ‘xerr’, ‘y’, ‘yerr’.
  • All positional arguments.