Python画柱状统计图操作示例【基于matplotlib库】

yipeiwu_com7年前Python基础

本文实例讲述了Python画柱状统计图操作。分享给大家供大家参考,具体如下:

一、工具:python的matplotlib.pyplot 库

二、案例:

import matplotlib.pyplot as plt
import numpy as np
#添加图形属性
plt.xlabel('Age range')
plt.ylabel('Number')
plt.title('The statistics of face age dataset')
a = plt.subplot(1, 1, 1)
plt.ylim=(10, 40000)
x = [10, 20, 30, 40, 50, 60, 70]
x1 = [7, 17, 27, 37, 47, 57, 67]
x2 = [13, 23, 33, 43, 53, 63, 73]
Y1 = [41, 39, 13, 69, 39, 14, 7]
Y2 = [0, 15, 20, 105, 79, 37, 43]
Y3 = [0, 91, 404, 464, 521, 375, 553]
#这里需要注意在画图的时候加上label在配合plt.legend()函数就能直接得到图例,简单又方便!
plt.bar(x1, Y1, facecolor='red', width=3, label = 'FG-NET')
plt.bar(x, Y2, facecolor='green', width=3, label = 'MORPH')
plt.bar(x2, Y3, facecolor='blue', width=3, label = 'CACD2000')
plt.legend()
plt.show()

效果图如下:

更多关于Python相关内容感兴趣的读者可查看本站专题:《Python数学运算技巧总结》、《Python数据结构与算法教程》、《Python函数使用技巧总结》、《Python字符串操作技巧汇总》、《Python入门与进阶经典教程》及《Python文件与目录操作技巧汇总》

希望本文所述对大家Python程序设计有所帮助。

相关文章

nohup后台启动Python脚本,log不刷新的解决方法

问题: =》nohup python3 xxxx.py &后台启动脚本 tail -100f nohup.out    -------->  &nbs...

django orm 通过related_name反向查询的方法

如下所示: class level(models.Model): l_name = models.CharField(max_length=50,verbose_name="等级名...

详解Django中CBV(Class Base Views)模型源码分析

详解Django中CBV(Class Base Views)模型源码分析

在view文件中编写一个类,并配置好路由 class Test(View): def get(self, request, *args, **kwargs): return Ht...

Python中类型关系和继承关系实例详解

本文详细介绍了Python中类型关系和继承关系。分享给大家供大家参考。具体分析如下: 如果一个对象A持有另一个对象B的ID,那么检索到A之后就可以检索到B,我们就说存在一个A到B的导航。...

简单讲解Python中的闭包

闭包并不是什么新奇的概念,它早在高级语言开始发展的年代就产生了。闭包(Closure)是词法闭包(Lexical Closure)的简称。对闭包的具体定义有很多种说法,这些说法大体可以分...