python – Whats the correct usage of matplotlib.mlab.normpdf()?

python – Whats the correct usage of matplotlib.mlab.normpdf()?

If you read documentation of matplotlib.mlab.normpdf, this function is deprycated and you should use scipy.stats.norm.pdf instead.

Deprecated since version 2.2: scipy.stats.norm.pdf

And because your distribution mean is about 222, you should use np.linspace(200, 220, 100).

So your code will look like:

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

meanAverage = 222.89219487179491    # typical value calculated beforehand
standardDeviation = 3.8857889432054091    # typical value calculated beforehand

x = np.linspace(200, 220, 100)
pyplot.plot(x, norm.pdf(x, meanAverage, standardDeviation))
pyplot.show()

It looks like you made a few small but significant errors. You either are choosing your x vector wrong or you swapped your stddev and mean. Since your mean is at 222, you probably want your x vector in this area, maybe something like 150 to 300. This way you get all the good stuff, right now you are looking at -3 to 3 which is at the tail of the distribution. Hope that helps.

python – Whats the correct usage of matplotlib.mlab.normpdf()?

I see that, for the *args which are sending meanAverage, standardDeviation, the correct thing to be sent is:

mu : a numdims array of means of a

sigma : a numdims array of atandard deviation of a

Does this help?

Leave a Reply

Your email address will not be published.