python统计并绘制频率分布直方图

python下绘制各种图形的代码块

http://www.218g.cn/?a=url&k=3a2a6dc4&u=aHR0cDovL3d3dy5sYWkxOC5jb20vY29udGVudC8yNDU4MzU2My5odG1s&t=5L2@55SoUHl0aG9u6L!b6KGM5o!P6L!w5oCn57uf6K6hLSBMYWkxOC5jb20gSVTmioDmnK@mlofnq6DmlLbol4@lpLk=&s=bnVtcHkg5rGC5LyX5pWw

为了统计XX数据的分布情况
从csv文件中读取出来数据,装换成int型的数组,再绘制出关于频率的直方图,
代码如下

from numpy import array
from numpy.random import normal
from matplotlib import pyplot


def get_data():
    n=0
    lenths=[]
    readfile=open("url_name_lenth.csv")
    lines=readfile.readlines()
    for line in lines:
        line=int(line)
        lenths.append(line)
        #
        n+=1
    print n 
    return array(lenths)

lenths=get_data()

def draw_hist(lenths):
    pyplot.hist(lenths,100)

    pyplot.xlabel('lenth')
    pyplot.xlim(0.0,400)
    pyplot.ylabel('Frequency')
    pyplot.title('Lenth Of Fake Urls')
    pyplot.show()

draw_hist(lenths)

你可能感兴趣的:(机器学习与数据挖掘)