首页 > 编程语言 > 详细

python Hisogram

时间:2014-10-24 20:23:13      阅读:380      评论:0      收藏:0      [点我收藏+]
# -*- coding: utf-8 -*-
"""
Created on Fri Oct 24 19:32:45 2014

@author: dell
"""

# -*- coding: utf-8 -*-
"""
Created on Fri Oct 17 09:14:25 2014
generate figure of bootstrap test result.
@author: dell
"""
import numpy as np
import matplotlib.pyplot as plt

def myfun(array, myrange, mystep):
    countList = []
    for item in myrange:
        tp = filter(lambda x: item + mystep > x >= item, array)
        countList.append(len(tp))
    return countList
    
if __name__ == __main__:
    #egdf = pd.read_csv(‘fig_table.csv‘, index_col = 0)
    mydata = np.random.rand(100) * 100
    
    fig = plt.figure()
    # Ka
    ax = fig.add_subplot(311)
    myrange, mystep = np.linspace(mydata.min(), mydata.max(), 101, retstep = True)
    eglist = myfun(mydata, myrange, mystep)
    ax.plot(myrange, eglist)
    ax.set_title(Ka)
    ax.legend([essential, non-essential], best)
    # new Ka
    ax = fig.add_subplot(312)
    n, bins, patches = plt.hist(mydata, bins = 100, range = (mydata.min(), mydata.max()), histtype = barstacked)
    
    # bp histogram
    ax = fig.add_subplot(313)
    hist2, bins2 = np.histogram(mydata, bins = 100, range = (mydata.min(), mydata.max()))
    ax.plot(bins2[:-1], hist2)
    plt.show()

Histogram

自己随意试验的三种方法。

注意的是 np.linspace(start, stop, num=50, endpoint=True, retstep=False) 指的是产生num个坐标,则整个line分为(num-1).

自己写的子函数,用来算数量。

python Hisogram

原文:http://www.cnblogs.com/hluo/p/4049133.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!