Plot Normal distribution with Matplotlib

后端 未结 2 1551
终归单人心
终归单人心 2020-12-07 10:02

please help me to plot the normal distribution of the folowing data:

DATA:

import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import         


        
2条回答
  •  盖世英雄少女心
    2020-12-07 10:49

    Assuming you're getting norm from scipy.stats, you probably just need to sort your list:

    import numpy as np
    import scipy.stats as stats
    import matplotlib.pyplot as plt
    
    h = [186, 176, 158, 180, 186, 168, 168, 164, 178, 170, 189, 195, 172,
         187, 180, 186, 185, 168, 179, 178, 183, 179, 170, 175, 186, 159,
         161, 178, 175, 185, 175, 162, 173, 172, 177, 175, 172, 177, 180]
    h.sort()
    hmean = np.mean(h)
    hstd = np.std(h)
    pdf = stats.norm.pdf(h, hmean, hstd)
    plt.plot(h, pdf) # including h here is crucial
    

    And so I get: enter image description here

提交回复
热议问题