bar函数是matplotlib用来画柱状图的工具,函数原型如下:
matplotlib.pyplot.bar(x, height, width=0.8, bottom=None, *, align=‘center’, data=None, **kwargs)
x : 定义柱状图的x轴
height : 定义柱高
width : 定义柱宽(默认值为0.8)
bottom : 可以是标量,也可以是列表等容器形式的值,用来定义柱高之下底部的高度,可用来在垂直方向叠加柱状图。
align : {‘center’, ‘edge’},确定柱状图在x轴上的位置偏向,center代表在x轴刻度上居中显示,edge代表在x轴刻度边缘显示
注意:若width为负值且align为edge,柱状图如图在x轴上靠左显示,反之靠右显示。
‘center’: Center the base on the x positions.
‘edge’: Align the left edges of the bars with the x positions.
To align the bars on the right edge pass a negative width and align=‘edge’.
Returns:
container : BarContainer
Container with all the bars and optionally errorbars.
返回对象是一个容器类型数据,顾名思义,该容器包含了柱状图的柱状信息
Other Parameters:
color : scalar or array-like, optional
可以统一或单独给柱状图每一个柱子指定颜色
edgecolor : scalar or array-like, optional
可以统一或单独给柱状图每一个柱子的边缘指定颜色
linewidth : scalar or array-like, optional
Width of the bar edge(s). If 0, don’t draw edges.
指定柱子边缘的线宽,若为0,则不显示柱子边缘线宽
tick_label : string or array-like, optional
The tick labels of the bars. Default: None (Use default numeric labels.)
这个在本人试验时没有发现效果
xerr, yerr : scalar or array-like of shape(N,) or shape(2,N), optional
If not None, add horizontal / vertical errorbars to the bar tips. The values are +/- sizes relative to the data:
scalar: symmetric +/- values for all bars
shape(N,): symmetric +/- values for each bar
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. (Default)
See Different ways of specifying error bars for an example on the usage of xerr and yerr.
ecolor : scalar or array-like, optional, default: ‘black’
The line color of the errorbars.
capsize : scalar, optional
The length of the error bar caps in points. Default: None, which will take the value from rcParams[“errorbar.capsize”].
error_kw : dict, optional
Dictionary of kwargs to be passed to the errorbar method. Values of ecolor or capsize defined here take precedence over the independent kwargs.
log : bool, optional, default: False
If True, set the y-axis to be log scale.
orientation : {‘vertical’, ‘horizontal’}, optional
This is for internal use only. Please use barh for horizontal bar plots. Default: ‘vertical’.