Python使用pylab绘制直方图

来源:互联网 发布:建行网络培训系统注册 编辑:程序博客网 时间:2024/05/22 12:42

Python直方图

#!/usr/bin/python# -*- coding: utf-8 -*-import pylab as pldataFile = "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("直方图标题")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
。。。


输出结果
这里写图片描述

0 0