Skip to content

Commit fb556ed

Browse files
dukebodyjorisvandenbossche
authored andcommitted
DOC: Improve pandas.Series.plot.kde docstring and kwargs rewording for whole file (#20041)
1 parent c3d491a commit fb556ed

File tree

1 file changed

+91
-26
lines changed

1 file changed

+91
-26
lines changed

pandas/plotting/_core.py

+91-26
Original file line numberDiff line numberDiff line change
@@ -2532,7 +2532,8 @@ def line(self, **kwds):
25322532
Parameters
25332533
----------
25342534
`**kwds` : optional
2535-
Keyword arguments to pass on to :py:meth:`pandas.Series.plot`.
2535+
Additional keyword arguments are documented in
2536+
:meth:`pandas.Series.plot`.
25362537
25372538
Returns
25382539
-------
@@ -2556,7 +2557,8 @@ def bar(self, **kwds):
25562557
Parameters
25572558
----------
25582559
`**kwds` : optional
2559-
Keyword arguments to pass on to :py:meth:`pandas.Series.plot`.
2560+
Additional keyword arguments are documented in
2561+
:meth:`pandas.Series.plot`.
25602562
25612563
Returns
25622564
-------
@@ -2571,7 +2573,8 @@ def barh(self, **kwds):
25712573
Parameters
25722574
----------
25732575
`**kwds` : optional
2574-
Keyword arguments to pass on to :py:meth:`pandas.Series.plot`.
2576+
Additional keyword arguments are documented in
2577+
:meth:`pandas.Series.plot`.
25752578
25762579
Returns
25772580
-------
@@ -2586,7 +2589,8 @@ def box(self, **kwds):
25862589
Parameters
25872590
----------
25882591
`**kwds` : optional
2589-
Keyword arguments to pass on to :py:meth:`pandas.Series.plot`.
2592+
Additional keyword arguments are documented in
2593+
:meth:`pandas.Series.plot`.
25902594
25912595
Returns
25922596
-------
@@ -2603,7 +2607,8 @@ def hist(self, bins=10, **kwds):
26032607
bins: integer, default 10
26042608
Number of histogram bins to be used
26052609
`**kwds` : optional
2606-
Keyword arguments to pass on to :py:meth:`pandas.Series.plot`.
2610+
Additional keyword arguments are documented in
2611+
:meth:`pandas.Series.plot`.
26072612
26082613
Returns
26092614
-------
@@ -2613,26 +2618,74 @@ def hist(self, bins=10, **kwds):
26132618

26142619
def kde(self, bw_method=None, ind=None, **kwds):
26152620
"""
2616-
Kernel Density Estimate plot
2621+
Kernel Density Estimate plot using Gaussian kernels.
2622+
2623+
In statistics, kernel density estimation (KDE) is a non-parametric way
2624+
to estimate the probability density function (PDF) of a random
2625+
variable. This function uses Gaussian kernels and includes automatic
2626+
bandwith determination.
26172627
26182628
Parameters
26192629
----------
2620-
bw_method: str, scalar or callable, optional
2621-
The method used to calculate the estimator bandwidth. This can be
2630+
bw_method : str, scalar or callable, optional
2631+
The method used to calculate the estimator bandwidth. This can be
26222632
'scott', 'silverman', a scalar constant or a callable.
26232633
If None (default), 'scott' is used.
26242634
See :class:`scipy.stats.gaussian_kde` for more information.
26252635
ind : NumPy array or integer, optional
2626-
Evaluation points. If None (default), 1000 equally spaced points
2627-
are used. If `ind` is a NumPy array, the kde is evaluated at the
2628-
points passed. If `ind` is an integer, `ind` number of equally
2629-
spaced points are used.
2630-
`**kwds` : optional
2631-
Keyword arguments to pass on to :py:meth:`pandas.Series.plot`.
2636+
Evaluation points for the estimated PDF. If None (default),
2637+
1000 equally spaced points are used. If `ind` is a NumPy array, the
2638+
kde is evaluated at the points passed. If `ind` is an integer,
2639+
`ind` number of equally spaced points are used.
2640+
kwds : optional
2641+
Additional keyword arguments are documented in
2642+
:meth:`pandas.Series.plot`.
26322643
26332644
Returns
26342645
-------
26352646
axes : matplotlib.AxesSubplot or np.array of them
2647+
2648+
See also
2649+
--------
2650+
scipy.stats.gaussian_kde : Representation of a kernel-density
2651+
estimate using Gaussian kernels. This is the function used
2652+
internally to estimate the PDF.
2653+
2654+
Examples
2655+
--------
2656+
Given a Series of points randomly sampled from an unknown
2657+
distribution, estimate this distribution using KDE with automatic
2658+
bandwidth determination and plot the results, evaluating them at
2659+
1000 equally spaced points (default):
2660+
2661+
.. plot::
2662+
:context: close-figs
2663+
2664+
>>> s = pd.Series([1, 2, 2.5, 3, 3.5, 4, 5])
2665+
>>> ax = s.plot.kde()
2666+
2667+
2668+
An scalar fixed bandwidth can be specified. Using a too small bandwidth
2669+
can lead to overfitting, while a too large bandwidth can result in
2670+
underfitting:
2671+
2672+
.. plot::
2673+
:context: close-figs
2674+
2675+
>>> ax = s.plot.kde(bw_method=0.3)
2676+
2677+
.. plot::
2678+
:context: close-figs
2679+
2680+
>>> ax = s.plot.kde(bw_method=3)
2681+
2682+
Finally, the `ind` parameter determines the evaluation points for the
2683+
plot of the estimated PDF:
2684+
2685+
.. plot::
2686+
:context: close-figs
2687+
2688+
>>> ax = s.plot.kde(ind=[1, 2, 3, 4, 5])
26362689
"""
26372690
return self(kind='kde', bw_method=bw_method, ind=ind, **kwds)
26382691

@@ -2645,7 +2698,8 @@ def area(self, **kwds):
26452698
Parameters
26462699
----------
26472700
`**kwds` : optional
2648-
Keyword arguments to pass on to :py:meth:`pandas.Series.plot`.
2701+
Additional keyword arguments are documented in
2702+
:meth:`pandas.Series.plot`.
26492703
26502704
Returns
26512705
-------
@@ -2660,7 +2714,8 @@ def pie(self, **kwds):
26602714
Parameters
26612715
----------
26622716
`**kwds` : optional
2663-
Keyword arguments to pass on to :py:meth:`pandas.Series.plot`.
2717+
Additional keyword arguments are documented in
2718+
:meth:`pandas.Series.plot`.
26642719
26652720
Returns
26662721
-------
@@ -2711,7 +2766,8 @@ def line(self, x=None, y=None, **kwds):
27112766
x, y : label or position, optional
27122767
Coordinates for each point.
27132768
`**kwds` : optional
2714-
Keyword arguments to pass on to :py:meth:`pandas.DataFrame.plot`.
2769+
Additional keyword arguments are documented in
2770+
:meth:`pandas.DataFrame.plot`.
27152771
27162772
Returns
27172773
-------
@@ -2728,7 +2784,8 @@ def bar(self, x=None, y=None, **kwds):
27282784
x, y : label or position, optional
27292785
Coordinates for each point.
27302786
`**kwds` : optional
2731-
Keyword arguments to pass on to :py:meth:`pandas.DataFrame.plot`.
2787+
Additional keyword arguments are documented in
2788+
:meth:`pandas.DataFrame.plot`.
27322789
27332790
Returns
27342791
-------
@@ -2745,7 +2802,8 @@ def barh(self, x=None, y=None, **kwds):
27452802
x, y : label or position, optional
27462803
Coordinates for each point.
27472804
`**kwds` : optional
2748-
Keyword arguments to pass on to :py:meth:`pandas.DataFrame.plot`.
2805+
Additional keyword arguments are documented in
2806+
:meth:`pandas.DataFrame.plot`.
27492807
27502808
Returns
27512809
-------
@@ -2762,7 +2820,8 @@ def box(self, by=None, **kwds):
27622820
by : string or sequence
27632821
Column in the DataFrame to group by.
27642822
`**kwds` : optional
2765-
Keyword arguments to pass on to :py:meth:`pandas.DataFrame.plot`.
2823+
Additional keyword arguments are documented in
2824+
:meth:`pandas.DataFrame.plot`.
27662825
27672826
Returns
27682827
-------
@@ -2781,7 +2840,8 @@ def hist(self, by=None, bins=10, **kwds):
27812840
bins: integer, default 10
27822841
Number of histogram bins to be used
27832842
`**kwds` : optional
2784-
Keyword arguments to pass on to :py:meth:`pandas.DataFrame.plot`.
2843+
Additional keyword arguments are documented in
2844+
:meth:`pandas.DataFrame.plot`.
27852845
27862846
Returns
27872847
-------
@@ -2806,7 +2866,8 @@ def kde(self, bw_method=None, ind=None, **kwds):
28062866
points passed. If `ind` is an integer, `ind` number of equally
28072867
spaced points are used.
28082868
`**kwds` : optional
2809-
Keyword arguments to pass on to :py:meth:`pandas.DataFrame.plot`.
2869+
Additional keyword arguments are documented in
2870+
:meth:`pandas.DataFrame.plot`.
28102871
28112872
Returns
28122873
-------
@@ -2825,7 +2886,8 @@ def area(self, x=None, y=None, **kwds):
28252886
x, y : label or position, optional
28262887
Coordinates for each point.
28272888
`**kwds` : optional
2828-
Keyword arguments to pass on to :py:meth:`pandas.DataFrame.plot`.
2889+
Additional keyword arguments are documented in
2890+
:meth:`pandas.DataFrame.plot`.
28292891
28302892
Returns
28312893
-------
@@ -2842,7 +2904,8 @@ def pie(self, y=None, **kwds):
28422904
y : label or position, optional
28432905
Column to plot.
28442906
`**kwds` : optional
2845-
Keyword arguments to pass on to :py:meth:`pandas.DataFrame.plot`.
2907+
Additional keyword arguments are documented in
2908+
:meth:`pandas.DataFrame.plot`.
28462909
28472910
Returns
28482911
-------
@@ -2863,7 +2926,8 @@ def scatter(self, x, y, s=None, c=None, **kwds):
28632926
c : label or position, optional
28642927
Color of each point.
28652928
`**kwds` : optional
2866-
Keyword arguments to pass on to :py:meth:`pandas.DataFrame.plot`.
2929+
Additional keyword arguments are documented in
2930+
:meth:`pandas.DataFrame.plot`.
28672931
28682932
Returns
28692933
-------
@@ -2888,7 +2952,8 @@ def hexbin(self, x, y, C=None, reduce_C_function=None, gridsize=None,
28882952
gridsize : int, optional
28892953
Number of bins.
28902954
`**kwds` : optional
2891-
Keyword arguments to pass on to :py:meth:`pandas.DataFrame.plot`.
2955+
Additional keyword arguments are documented in
2956+
:meth:`pandas.DataFrame.plot`.
28922957
28932958
Returns
28942959
-------

0 commit comments

Comments
 (0)