ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

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

2021-05-13 19:58:03  阅读:16  来源: 互联网

标签:plt bar color pyplot float values kwargs array


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

标签:plt,bar,color,pyplot,float,values,kwargs,array
来源: https://blog.csdn.net/Crystal_remember/article/details/116758131

专注分享技术,共同学习,共同进步。侵权联系[admin#icode9.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有