Repository navigation
DOC: improve the vonmises docstring example - #5814
Conversation
There was a problem hiding this comment.
Tested? I note that y is no longer normalized.
There was a problem hiding this comment.
Right, y is not divided by its maximum value anymore. But why were they doing that originally? I think that with this change, both the histogram and pdf should integrate to ~1.0.
There was a problem hiding this comment.
I'm guessing that the curve was supposed to pass through the tops of the histogram bars. Might be worth running a check...
There was a problem hiding this comment.
No, the normed argument of hist normalizes the area not the maximum. So in http://docs.scipy.org/doc/numpy/reference/generated/numpy.random.vonmises.html the histogram has area 1.0 but the density curve has maximum 1.0, and it's mostly a coincidence that the maximum of the histogram is also near 1.0. If not for this coincidence, the problems mentioned in #5811 probably would have been found sooner.
There was a problem hiding this comment.
I'm not arguing at this point ;) I'd just like to see the plot...
import numpy as np
mu, kappa = 0.0, 4.0 # mean and dispersion
s = np.random.vonmises(mu, kappa, 1000)
# Display the histogram of the samples, along with
# the probability density function:
import matplotlib.pyplot as plt
from scipy.special import i0
plt.hist(s, 50, normed=True)
x = np.linspace(-np.pi, np.pi, num=51)
y = np.exp(kappa*np.cos(x-mu))/(2*np.pi*i0(kappa))
plt.plot(x, y, linewidth=2, color='r')
plt.savefig('vonmises.png')This depends on the random number seed, and it uses the same number of samples and bins as before. Increasing the number of samples will make the histogram agree more closely with the curve. |
DOC: improve the vonmises docstring example
|
Great, thanks @argriffing . |

closes #5811