博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
matplotlib 柱状图 Bar Chart 样例及参数
阅读量:4548 次
发布时间:2019-06-08

本文共 1163 字,大约阅读时间需要 3 分钟。

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]
设置xerr=4
设置yerr=1,ecolor='#999999'
 
转载至 http://blog.sina.com.cn/s/blog_b09d4602010194wy.html

转载于:https://www.cnblogs.com/linyujin/p/9895328.html

你可能感兴趣的文章
2、文件夹
查看>>
win10企业版无法访问共享文件夹
查看>>
查行号
查看>>
《学习之道》第三章学习方法12批评使我们更优秀
查看>>
猫眼首页
查看>>
最短路之dijkstra算法
查看>>
SHDP--Working With HBase (二)之HBase JDBC驱动Phoenix与SpringJDBCTemplate的集成
查看>>
Mac显示器不亮
查看>>
luogu P2312 解方程
查看>>
Cordova开发速记
查看>>
Chrome开发工具
查看>>
MySQL 的 RowNum 实现
查看>>
windows 控制台下运行cl命令
查看>>
(七十八)使用第三方框架INTULocationManager实现定位
查看>>
LeetCode问题:搜索插入位置
查看>>
JVM基础学习之基本概念、可见性与同步
查看>>
UML入门
查看>>
CodeForces - 524F And Yet Another Bracket Sequence
查看>>
python学习笔记-day10-2【多进程,多线程】
查看>>
Atitit 图像处理 平滑 也称 模糊, 归一化块滤波、高斯滤波、中值滤波、双边滤波)...
查看>>