matplotlib.pyplot.bar() plt.bar()

matplotlib.pyplot.bar(xheightwidth=0.8bottom=None*align='center'data=None**kwargs)

功能

此函数用来画条形图

参数

         x:为条形图的横坐标,格式float or array-like

         height:条形图的高,格式float or array-like

         width:条形图的宽,格式loat or array-like, 默认为0.8

        bottom:The y coordinate(s) of the bars bases.格式float or array-like, 默认为0

        align:矩形条与x的对齐方式,默认为中心对齐,如下左图所示。如果要对齐右边的线条,如下右图所示,可以将宽度置为负数(如width = -1)且令  align='edge'。 

                                                                                                                   

        **kwargs:矩形的属性

       另外还有一些其他参数,如 color:设置条形的颜色。edgecolor:设置条形的边缘颜色 等,具体参见文章尾部。

 

例子

names = [1,2,3,4]
values = ['hight0','high1','high2','high3']
thisplot = plt.bar(names, values,color="#777777") #设置默认灰色
#thisplot = plt.bar(names, values,width = -1,align='edge',color="#777777")  #设置bar为右对齐
thisplot[1].set_color('yellow')
thisplot[2].set_color('#000000') #黑色
plt.show()

结果

其他参数以及矩形的属性( **kwargs)

 

Other Parameters:

 

linewidth:矩形条的边的宽度,0为不画边。float or array-like, optional

 

tick_label:矩形条的标识,默认无 。str or list of str, optional

 

xerr, yerrfloat 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)

 

ecolor color or list of color, default: 'black'

The line color of the errorbars.

capsizefloat, default: rcParams["errorbar.capsize"] (default: 0.0)

The length of the error bar caps in points.

error_kwdict, optional

Dictionary of kwargs to be passed to the errorbar method. Values of ecolor or capsize defined here take precedence over the independent kwargs.

logbool, default: False

If True, set the y-axis to be log scale.

 

**kwargs:矩形属性

PropertyDescription
agg_filtera filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array
alphascalar or None
animatedbool
antialiased or aaunknown
capstyleCapStyle or {'butt', 'projecting', 'round'}
clip_boxBbox
clip_onbool
clip_pathPatch or (Path, Transform) or None
colorcolor
containsunknown
edgecolor or eccolor or None or 'auto'
facecolor or fccolor or None
figureFigure
fillbool
gidstr
hatch{'/', '\', '|', '-', '+', 'x', 'o', 'O', '.', '*'}
in_layoutbool
joinstyleJoinStyle or {'miter', 'round', 'bevel'}
labelobject
linestyle or ls{'-', '--', '-.', ':', '', (offset, on-off-seq), ...}
linewidth or lwfloat or None
path_effectsAbstractPathEffect
pickerNone or bool or float or callable
rasterizedbool
sketch_params(scale: float, length: float, randomness: float)
snapbool or None
transformTransform
urlstr
visiblebool
zorderfloat

 

注:

参考文献

https://matplotlib.org/stable/gallery/misc/table_demo.html#sphx-glr-gallery-misc-table-demo-py

https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.bar.html?highlight=bar#matplotlib.pyplot.bar

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Alocus_

如果我的内容帮助到你,打赏我吧

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值