脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - Python - Python使用pylab库实现绘制直方图功能示例

Python使用pylab库实现绘制直方图功能示例

2021-02-28 00:03早起的小小鸟 Python

这篇文章主要介绍了Python使用pylab库实现绘制直方图功能,结合实例形式分析了Python数据读取、遍历以及基于pylab库绘制直方图的相关操作技巧,需要的朋友可以参考下

本文实例讲述了Python使用pylab库实现绘制直方图功能。分享给大家供大家参考,具体如下:

Python直方图

?
1
2
3
4
5
6
7
8
9
10
11
12
#!/usr/bin/python
# -*- coding: utf-8 -*-
import pylab as pl
dataFile = "dataList.txt"
tempList = []
with open(dataFile,"r") as data:
  for everLine in data:
    arrEverLine = [float(index) for index in everLine.split()]
    tempList.append(arrEverLine[0])
pl.hist(tempList,100)
pl.xlabel("直方图标题", fontproperties='SimHei')
pl.show()

dataList.txt内容

14 2 1 0.5 0.5 0 1 0.5 1.5 18.5
19 2 2 0.5 1 0 1 0.5 0 21
19.5 2 1.5 2 0 0.5 2 0 1 20
17.5 1.5 1 1.5 2 0 1.5 0 0 18.5
19.5 2 2 2 0.5 0 1 0 0.5 19.5
16.5 2 0.5 1 0 0.5 0.5 0 0.5 19.5
15.5 2 1 1.5 0 0 1 0.5 1 17.5
13.5 1.5 1 1 2 0 2 0.5 2 20
14.5 2 1.5 2 0 0 1 0 2 18.5
16 2 2 1.5 1 0.5 1 0 2 19.5
。。。

输出结果

Python使用pylab库实现绘制直方图功能示例

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

原文链接:https://blog.csdn.net/yiduanchengxu/article/details/50264021

延伸 · 阅读

精彩推荐