python: plotting a histogram with a function line on top

后端 未结 3 1525
情书的邮戳
情书的邮戳 2021-02-04 04:35

I\'m trying to do a little bit of distribution plotting and fitting in Python using SciPy for stats and matplotlib for the plotting. I\'m having good luck with some things like

3条回答
  •  清酒与你
    2021-02-04 05:07

    One could be interested in plotting the distibution function of any histogram. This can be done using seaborn kde function

    import numpy as np # for random data
    import pandas as pd  # for convinience
    import matplotlib.pyplot as plt  # for graphics
    import seaborn as sns  # for nicer graphics
    
    v1 = pd.Series(np.random.normal(0,10,1000), name='v1')
    v2 = pd.Series(2*v1 + np.random.normal(60,15,1000), name='v2')
    
    # plot a kernel density estimation over a stacked barchart
    plt.figure()
    plt.hist([v1, v2], histtype='barstacked', normed=True);
    v3 = np.concatenate((v1,v2))
    sns.kdeplot(v3);
    plt.show()
    

    from a coursera course on data visualization with python

提交回复
热议问题