python可视化之直方图的绘制

来源:互联网 发布:万网域名转移godaddy 编辑:程序博客网 时间:2024/05/30 05:41

本文绘制直方图使用的数据集为Iris,下载地址在http://archive.ics.uci.edu/ml/。

from matplotlib import pyplot as plt'''count of Petal width''' file=open("../dataset/iris.txt", "r")content = [x.rstrip("\n") for x in file]file.close()d_sl=[]while '' in content:    content.remove('')data_slength = [x.split(',')[3] for x in content[0:]]while '' in data_slength:    data_slength.remove('')for i in data_slength:    d_sl.append(float(i))plt.hist(d_sl,10,alpha=0.5)plt.xlabel("Petal width")plt.ylabel("count")plt.show()

这里以Petal width为例,绘制结果如下:
这里写图片描述

0 0
原创粉丝点击