Skip to content

Commit

Permalink
DOC: Improve pandas.Series.plot.kde docstring.
Browse files Browse the repository at this point in the history
  • Loading branch information
dukebody committed Mar 7, 2018
1 parent aedbd94 commit b4bcd58
Showing 1 changed file with 55 additions and 8 deletions.
63 changes: 55 additions & 8 deletions pandas/plotting/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2604,26 +2604,73 @@ def hist(self, bins=10, **kwds):

def kde(self, bw_method=None, ind=None, **kwds):
"""
Kernel Density Estimate plot
Kernel Density Estimate plot using Gaussian kernels.
In statistics, kernel density estimation (KDE) is a non-parametric way
to estimate the probability density function (PDF) of a random
variable. This function uses Gaussian kernels and includes automatic
bandwith determination.
Parameters
----------
bw_method: str, scalar or callable, optional
The method used to calculate the estimator bandwidth. This can be
bw_method : str, scalar or callable, optional
The method used to calculate the estimator bandwidth. This can be
'scott', 'silverman', a scalar constant or a callable.
If None (default), 'scott' is used.
See :class:`scipy.stats.gaussian_kde` for more information.
ind : NumPy array or integer, optional
Evaluation points. If None (default), 1000 equally spaced points
are used. If `ind` is a NumPy array, the kde is evaluated at the
points passed. If `ind` is an integer, `ind` number of equally
spaced points are used.
`**kwds` : optional
Evaluation points for the estimated PDF. If None (default),
1000 equally spaced points are used. If `ind` is a NumPy array, the
kde is evaluated at the points passed. If `ind` is an integer,
`ind` number of equally spaced points are used.
kwds : optional
Keyword arguments to pass on to :py:meth:`pandas.Series.plot`.
Returns
-------
axes : matplotlib.AxesSubplot or np.array of them
See also
--------
:class:`scipy.stats.gaussian_kde` : Representation of a kernel-density
estimate using Gaussian kernels. This is the function used
internally to estimate the PDF.
Examples
--------
Given a ``Series`` of points randomly sampled from an unknown
distribution, estimate this distribution using KDE with automatic
bandwidth determination and plot the results, evaluating them at
1000 equally spaced points (default):
.. plot::
:context: close-figs
>>> s = pd.Series([1, 2, 2.5, 3, 3.5, 4, 5])
>>> p = s.plot.kde()
An scalar fixed bandwidth can be specified. Using a too small bandwidth
can lead to overfitting, while a too large bandwidth can result in
underfitting:
.. plot::
:context: close-figs
>>> p = s.plot.kde(bw_method=3)
.. plot::
:context: close-figs
>>> p = s.plot.kde(bw_method=0.3)
Finally, the `ind` parameter determines the evaluation points for the
plot of the estimated PDF:
.. plot::
:context: close-figs
>>> p = s.plot.kde(ind=[1, 2, 3, 4, 5])
"""
return self(kind='kde', bw_method=bw_method, ind=ind, **kwds)

Expand Down

0 comments on commit b4bcd58

Please sign in to comment.