import numpy as np
import matplotlib.pyplot as plt # 柱形图
# 例一
N =5
y = [15,28,10,30,25]
index = np.arange(N)
p = plt.bar(index,height=y)
plt.show() # 例2
p1 = plt.bar(0,bottom=index,width=y,height=0.5,align='edge',color='red',orientation='horizontal')
plt.show() p2 = plt.barh(index,width= y , align='edge',color ='green',height=0.5)
plt.show() # 例3
sales_BJ = [52,55,63,53]
sales_SH = [44,66,55,41] index = np.arange(4)
bar_width = 0.3 # 竖着显示
plt.bar(index,sales_BJ,bar_width)
plt.bar(index+bar_width,sales_SH,bar_width,color='r')
plt.show() # 横着显示
plt.barh(index,sales_BJ,bar_width)
plt.barh(index+bar_width,sales_SH,bar_width,color='r')
plt.show() # 层叠图
plt.bar(index,sales_BJ,bar_width)
plt.bar(index,sales_SH,bar_width,color='r',bottom=sales_BJ)
plt.show() # 练习
'''
生成两组大小为5的数据;
画出两组数据 水平的条形图;
采用并列,层叠两种方式; ''' N =5
n1 = np.random.randint(1,100,N)
n2 = np.random.randint(1,100,N) index = np.arange(N)
bar_width = 0.3 # 并列显示
plt.bar(index,n1,bar_width)
plt.bar(index+bar_width,n2,bar_width,color='r')
plt.show() # 层叠显示
plt.bar(index,n1,bar_width)
plt.bar(index,n2,bar_width,color='r',bottom=n1)
plt.show()

在未来面前,我们永远都是孩子。不断思考,不断学习,才能让我们走的更远。

个人主页:https://www.oceaneyes.cn/

个人学习博客:http://oceaneyes.top/

CSDN:https://blog.csdn.net/qq_16123129

长按二维码关注,一起交流学习~~~

04-matplotlib-柱形图的更多相关文章

  1. matplotlib模块详解

    简单绘图,折线图,并保存为图片 import matplotlib.pyplot as plt x=[1,2,3,4,5] y=[10,5,15,10,20] plt.plot(x,y,'ro-',c ...

  2. 在Ubuntu 14.04 64bit上安装numpy和matplotlib库

    原文:http://blog.csdn.net/tao_627/article/details/44004541 按照这个成功安装! 机器学习是数据挖掘的一种实现形式,在学习<机器学习实战> ...

  3. Matplotlib学习---用matplotlib画柱形图,堆积柱形图,横向柱形图(bar chart)

    这里利用Nathan Yau所著的<鲜活的数据:数据可视化指南>一书中的数据,学习画图. 数据地址:http://datasets.flowingdata.com/hot-dog-cont ...

  4. Linux入门(10)——Ubuntu16.04使用pip3和pip安装numpy,scipy,matplotlib等第三方库

    安装Python3第三方库numpy,scipy,matplotlib: sudo apt install python3-pip pip3 install numpy pip3 install sc ...

  5. Ubuntu10.04 python2.6下安装matplotlib环境

    一.准备工作1.sudo apt-get install python-numpy2.sudo apt-get install python2.6-dev3.sudo apt-get install ...

  6. ubuntu18.04下安装Anaconda及numpy、matplotlib

    为了学习深度学习,我需要首先掌握利用python进行科学计算的知识,顺便复习一下线性代数.微积分.概率论.当然,现在我要做的是安装Anaconda. 1.官网下载,linux版本:https://ww ...

  7. Ubuntu16.04 解决matplotlib乱码或者中文显示不了的问题(可用)

    一. 下载字体 SimHei.ttf 复制到linux字体库中 sudo cp ~/SimHei.ttf /usr/share/fonts/SimHei.ttf 二.查看matplotlib配置 In ...

  8. Ubuntu 16.04 LTS下matplotlib安装出错

    使用命令sudo pip3 install matplotlib已知报错,用同样的命令安装numpy和opencv却没有,因此重装linux系统两次都没有解决(我是在Vmware中创建的).报错如下: ...

  9. Ubuntu 18.04安装 pyenv、pyenv-virtualenv、virtualenv、Numpy、SciPy、Pillow、Matplotlib

    1.目前Python版本管理工具有很多,pyenv是比较好用的一款,安装如下: 输入: git clone https://github.com/pyenv/pyenv.git ~/.pyenv ec ...

  10. 2018.04.02 matplotlib 图名,图例,轴标签,轴边界,轴刻度,轴刻度标签

    import numpy as np import pandas as pd import matplotlib.pyplot as plt df = pd.DataFrame(np.random.r ...

随机推荐

  1. robotframwork的WEB功能测试(二)—登录

    小结一下截止到目前,我接触的系统的登录模拟. 1. 带token的session:这种用抓包工具很容易抓到,使用这个链接就可以模拟已登录. 2. 使用cookie:有的系统是判断cookie来判断是否 ...

  2. oracle之修改/忘记用户密码

    一.修改/忘记用户密码: ## 修改oracle用户名和密码 sqlplus /nolog ## DBA角色进入 conn /as sysdba; ## 查看用户列表 select username ...

  3. centos6.5添加阿里docker加速器

    1. 配置阿里docker加速器 vi /etc/sysconfig/docker 在文件末尾追加下面两行 other_args="--registry-mirror=https://pl8 ...

  4. 集合之Vector

    在java提高篇(二一)—–ArrayList.java提高篇(二二)—LinkedList,详细讲解了ArrayList.linkedList的原理和实现过程,对于List接口这里还介绍一个它的实现 ...

  5. 集合之HashTable

    在java中与有两个类都提供了一个多种用途的hashTable机制,他们都可以将可以key和value结合起来构成键值对通过put(key,value)方法保存起来,然后通过get(key)方法获取相 ...

  6. Linux下Meepops的搭建

    1.下载跟版本相对应的扩展 http://br.php.net/downloads.php 2.进入到pcntl目录 cd php-5.4.45/ext/pcntl 3.先执行phpize /usr/ ...

  7. JS实现sleep()方法

    这种实现方式是利用一个伪死循环阻塞主线程.因为JS是单线程的.所以通过这种方式可以实现真正意义上的sleep(). function sleep(delay) { var start = (new D ...

  8. 使用CSS3的“transition ”属性控制长宽度的缓慢变化

    有时候我们可能会想要改变某个资源信息的长宽度,比如改变某个div的宽度,而且需要让这个宽度缓慢改变,而不是突然就改变了.这时候你可能会想到使用jquery的animate()函数,不过这个方法既得引用 ...

  9. POJ 1080( LCS变形)

    题目链接: http://poj.org/problem?id=1080 Human Gene Functions Time Limit: 1000MS   Memory Limit: 10000K ...

  10. H.264编码格式简单分析

    H.264的重要性不再提了.本文主要记录一下H.264的编码格式.H.264官方文档:https://github.com/jiayayao/DataSheet/tree/master/encode- ...