Skip to content

Commit

Permalink
DOC: stats.vonmises: improve documentation (scipy#18384)
Browse files Browse the repository at this point in the history
* DOC: stats.vonmises: improve documentation
  • Loading branch information
dschmitz89 committed May 5, 2023
1 parent b0d1a4c commit 91210d7
Showing 1 changed file with 63 additions and 3 deletions.
66 changes: 63 additions & 3 deletions scipy/stats/_continuous_distns.py
Original file line number Diff line number Diff line change
Expand Up @@ -9971,11 +9971,71 @@ class vonmises_gen(rv_continuous):
`vonmises_line` is the same distribution, defined on :math:`[-\pi, \pi]`
on the real line. This is a regular (i.e. non-circular) distribution.
`vonmises` and `vonmises_line` take ``kappa`` as a shape parameter.
Note about distribution parameters: `vonmises` and `vonmises_line` take
``kappa`` as a shape parameter (concentration) and ``loc`` as the location
(circular mean). A ``scale`` parameter is accepted but does not have any
effect.
%(after_notes)s
Examples
--------
Import the necessary modules.
%(example)s
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> from scipy.stats import vonmises
Define distribution parameters.
>>> loc = 0.5 * np.pi # circular mean
>>> kappa = 1 # concentration
Compute the probability density at ``x=0`` via the ``pdf`` method.
>>> vonmises.pdf(loc, kappa, 0)
0.12570826359722018
Verify that the percentile function ``ppf`` inverts the cumulative
distribution function ``cdf`` up to floating point accuracy.
>>> x = 1
>>> cdf_value = vonmises.cdf(loc=loc, kappa=kappa, x=x)
>>> ppf_value = vonmises.ppf(cdf_value, loc=loc, kappa=kappa)
>>> x, cdf_value, ppf_value
(1, 0.31489339900904967, 1.0000000000000004)
Draw 1000 random variates by calling the ``rvs`` method.
>>> number_of_samples = 1000
>>> samples = vonmises(loc=loc, kappa=kappa).rvs(number_of_samples)
Plot the von Mises density on a Cartesian and polar grid to emphasize
that is is a circular distribution.
>>> fig = plt.figure(figsize=(12, 6))
>>> left = plt.subplot(121)
>>> right = plt.subplot(122, projection='polar')
>>> x = np.linspace(-np.pi, np.pi, 500)
>>> vonmises_pdf = vonmises.pdf(loc, kappa, x)
>>> ticks = [0, 0.15, 0.3]
The left image contains the Cartesian plot.
>>> left.plot(x, vonmises_pdf)
>>> left.set_yticks(ticks)
>>> number_of_bins = int(np.sqrt(number_of_samples))
>>> left.hist(samples, density=True, bins=number_of_bins)
>>> left.set_title("Cartesian plot")
>>> left.set_xlim(-np.pi, np.pi)
>>> left.grid(True)
The right image contains the polar plot.
>>> right.plot(x, vonmises_pdf, label="PDF")
>>> right.set_yticks(ticks)
>>> right.hist(samples, density=True, bins=number_of_bins,
... label="Histogram")
>>> right.set_title("Polar plot")
>>> right.legend(bbox_to_anchor=(0.15, 1.06))
"""
def _shape_info(self):
Expand Down

0 comments on commit 91210d7

Please sign in to comment.