0

I am generating normal distributions from the mean and standard deviation of a dataset with this code:

sampledRow = dataset.sample()  # Get random item from the dataset
x = np.linspace(-10, 10, 1000)  # Create X axis -10 to 10
# Normal Distribution using datas mean and sigma
y = norm.pdf(x, loc=sampledRow['Mean'], scale=sampledRow['Sigma'])

plt.plot(x, y)
plt.vlines(sampledRow['Fitness'], ymin=0, ymax=max(y), linestyles='--')

plt.show()
plt.close()

Some of my plots appear almost correct (figure 1), but unfortunately most of my plots look like figure 2 in which the y-axis goes far above 1. How can I change the way I handle my data to make the y-axis show probability density (proportion of probability of 100%), while maintaining a normal distribution?

Thank you!

Figure 1 enter image description here

Mean = -5.3, Sigma = 0.58

Figure 2 enter image description here

Mean = -1.1, Sigma = 0.065

Paul
  • 165
  • 1
  • 12
  • 4
    Well, it is perfectly logical that the probability density function for a narrow sigma gets larger than 1. The probability density function is normalized such that the total area is equal to one. See e.g. [Normed histogram y-axis larger than 1](https://stackoverflow.com/questions/61881175/normed-histogram-y-axis-larger-than-1) – JohanC Feb 24 '22 at 17:25
  • Oh I see, that makes perfect sense!! I suppose I was thinking of it in the terms of cumulative probability plots so I had it in my head that it should be going to 1. I appreciate the help!! – Paul Feb 24 '22 at 17:35

0 Answers0