zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    洛谷 P1064 金明的预算方案
    洛谷 P2015 二叉苹果树
    洛谷 P1471 方差
    洛谷 P1198 [JSOI2008]最大数
    js字符串中的比较类以及截取类substring实例
    字符串indexOf()的用法
    fromCharCode返回字符串以及字符串加密
    字符串获取类、封装检测数字的方法
    原生js解决倒计时结束图片抖动之后移动消失的效果
    原生js解决图片渐渐变透明的效果
  • 原文地址:https://www.cnblogs.com/linyujin/p/9895328.html
Copyright © 2011-2022 走看看