matplotlib 柱状图 Bar Chart 样例及参数

def bar_chart_generator():
    l = [1,2,3,4,5]
    h = [20, 14, 38, 27, 9]
    w = [0.1, 0.2, 0.3, 0.4, 0.5]
    b = [1,2,3,4,5]
 
    fig = plt.figure()
    ax = fig.add_subplot(111)
    rects = ax.bar(l, h, w, b,
                   color='#ffff00',
                   edgecolor='#000000',
                   linewidth=2,
                   #xerr=4,
                   #yerr=1,
                   #ecolor='#999999',
                   #capsize=10,
                   #align='center',
                   #orientation='horizontal',
                  )
    plt.savefig('bar.png')
==================================
 
函数原型:
matplotlib.pyplot.bar(left, height, width=0.8, bottom=None, hold=None, **kwargs)
 
基本参数:
left        每个柱x轴左边界
bottom      每个柱y轴下边界
height      柱高度(Y轴方向) 
width       柱宽度(X轴方向)
以上参数可以设置为数值或者list
但要保证如果为list, len(list)要一致
绘制的方形为:
    X: left   --- left+width
    Y: bottom --- bottom+height
返回值:
    matplotlib.patches.Rectangle
 
柱状图使用bottom扩展即可化为甘特图 Gantt Chart
 
其他参数:
color       Bar颜色
edgecolor   Bar边界线颜色
align       可选['left'(default) | 'center']
            决定整个bar图分布
            默认left表示默认从左边界开始绘制,center会将图绘制在中间位置
 
xerr        x方向error bar
yerr        y方向error bar
ecolor      error bar颜色
capsize     error bar横线宽度(default 3)
 
样例:
基本设置
l = [1,2,3,4,5]
h = [20, 14, 38, 27, 9]
w = [0.1, 0.2, 0.3, 0.4, 0.5]
b = [1,2,3,4,5]
matplotlib <wbr>柱状图 <wbr>Bar <wbr>Chart <wbr>样例及参数
设置xerr=4
matplotlib <wbr>柱状图 <wbr>Bar <wbr>Chart <wbr>样例及参数
设置yerr=1,ecolor='#999999'
matplotlib <wbr>柱状图 <wbr>Bar <wbr>Chart <wbr>样例及参数
 
转载至 http://blog.sina.com.cn/s/blog_b09d4602010194wy.html

posted on 2018-11-02 11:31  可能是小林吧  阅读(10274)  评论(0编辑  收藏  举报

导航