2015-02-24 138 views
1

目前在單個直方圖中有3組數據,但我需要爲每組數據繪製一條曲線。目前通過函數繪製直方圖:Matplotlib:使用直方圖數據繪製曲線

def plot_histogram(xmin,xmax,title,xlabel,data,data1,data2): 
    plt.xlim(xmin, xmax) 
    plt.title(title) 
    plt.xlabel(xlabel) 
    plt.ylabel('Relative Frequency') 
    bins=np.histogram(np.hstack((data,data1,data2)), bins=11)[1] 
    plt.hist([data, data1, data2], bins, normed=1, alpha=0.5, color=['b', 'g', 'r'], label=['t', 'g-', 'g+']) 
    plt.legend(loc='upper right') 
    plt.show() 

如何繪製每個直方圖形狀的曲線或線?

+0

你可能想看看核密度估計(KDE)。在我看來,'熊貓'是繪製KDE的最簡單方法。 – cel 2015-02-24 17:50:42

+0

我一直在研究KDE,我發現這個資源應該有所幫助(http://nbviewer.ipython.org/github/mwaskom/seaborn/blob/master/examples/plotting_distributions.ipynb),但不幸的是,seaborn贏得了'安裝在我的電腦上。 你有沒有其他的指針? – Charlietrypsin 2015-02-25 18:30:31

回答