2016-02-14 26 views
1

我想创建一个样本,其价值所在的频率曲线1和1matplotlib HIST给我“太多值解压”

使用numpy的创建该直方图之间工作得很好:

freq, bins = np.histogram(sample, bins=np.arange(-1,1,0.05)) 

但是创建使用相同的二进制位的情节给我一个错误(见题):

plt.hist(freq, range=bins) 

除此之外,怎么可能调整的X标签,从而把正确的bin值是显示?

最小工作示例:

import matplotlib.pyplot as plt 
import numpy as np 


if __name__ == "__main__": 

    sample = np.random.uniform(-1,1,100) 
    freq, bins = np.histogram(sample, bins=np.arange(-1,1,0.05)) 

    plt.figure() 
    plt.hist(freq, range=bins) 
    plt.show() 
+1

请包括这里的小例子,该pastebin链接可能会过期。 – timgeb

+0

这是应该做什么?您不会传递频率,但会将样本传递给'plt.hist'。 – cel

+0

你可以自己回答这个问题,通过写一个自己的答案来标记为“已回答”,或者你可以删除问题。但是,删除的问题无法支持其他人...... – albert

回答

0

这不是必要的预处理使用numpy的数据,只需将数据传递直接到matplotlib的HIST功能:

sample = np.random.uniform(-1,1,10000) 
    #freq, bins = np.histogram(sample, bins=np.arange(-1,1,0.05)) 

    plt.figure() 
    plt.hist(sample, bins=100) 
    plt.show()