@@ -1380,6 +1380,50 @@ def orientation(self):
13801380 return 'vertical'
13811381
13821382
1383+ _kde_docstring = """
1384+ Generate Kernel Density Estimate plot using Gaussian kernels.
1385+
1386+ In statistics, `kernel density estimation`_ (KDE) is a non-parametric
1387+ way to estimate the probability density function (PDF) of a random
1388+ variable. This function uses Gaussian kernels and includes automatic
1389+ bandwith determination.
1390+
1391+ .. _kernel density estimation:
1392+ https://en.wikipedia.org/wiki/Kernel_density_estimation
1393+
1394+ Parameters
1395+ ----------
1396+ bw_method : str, scalar or callable, optional
1397+ The method used to calculate the estimator bandwidth. This can be
1398+ 'scott', 'silverman', a scalar constant or a callable.
1399+ If None (default), 'scott' is used.
1400+ See :class:`scipy.stats.gaussian_kde` for more information.
1401+ ind : NumPy array or integer, optional
1402+ Evaluation points for the estimated PDF. If None (default),
1403+ 1000 equally spaced points are used. If `ind` is a NumPy array, the
1404+ KDE is evaluated at the points passed. If `ind` is an integer,
1405+ `ind` number of equally spaced points are used.
1406+ **kwds : optional
1407+ Additional keyword arguments are documented in
1408+ :meth:`pandas.%(this-datatype)s.plot`.
1409+
1410+ Returns
1411+ -------
1412+ axes : matplotlib.AxesSubplot or np.array of them
1413+
1414+ See Also
1415+ --------
1416+ scipy.stats.gaussian_kde : Representation of a kernel-density
1417+ estimate using Gaussian kernels. This is the function used
1418+ internally to estimate the PDF.
1419+ %(sibling-datatype)s.plot.kde : Generate a KDE plot for a
1420+ %(sibling-datatype)s.
1421+
1422+ Examples
1423+ --------
1424+ %(examples)s
1425+ """
1426+
13831427class KdePlot (HistPlot ):
13841428 _kind = 'kde'
13851429 orientation = 'vertical'
@@ -2616,47 +2660,10 @@ def hist(self, bins=10, **kwds):
26162660 """
26172661 return self (kind = 'hist' , bins = bins , ** kwds )
26182662
2619- def kde (self , bw_method = None , ind = None , ** kwds ):
2620- """
2621- Generate Kernel Density Estimate plot using Gaussian kernels.
2622-
2623- In statistics, `kernel density estimation`_ (KDE) is a non-parametric
2624- way to estimate the probability density function (PDF) of a random
2625- variable. This function uses Gaussian kernels and includes automatic
2626- bandwith determination.
2627-
2628- .. _kernel density estimation:
2629- https://en.wikipedia.org/wiki/Kernel_density_estimation
2630-
2631- Parameters
2632- ----------
2633- bw_method : str, scalar or callable, optional
2634- The method used to calculate the estimator bandwidth. This can be
2635- 'scott', 'silverman', a scalar constant or a callable.
2636- If None (default), 'scott' is used.
2637- See :class:`scipy.stats.gaussian_kde` for more information.
2638- ind : NumPy array or integer, optional
2639- Evaluation points for the estimated PDF. If None (default),
2640- 1000 equally spaced points are used. If `ind` is a NumPy array, the
2641- KDE is evaluated at the points passed. If `ind` is an integer,
2642- `ind` number of equally spaced points are used.
2643- **kwds : optional
2644- Additional keyword arguments are documented in
2645- :meth:`pandas.Series.plot`.
2646-
2647- Returns
2648- -------
2649- axes : matplotlib.AxesSubplot or np.array of them
2650-
2651- See Also
2652- --------
2653- scipy.stats.gaussian_kde : Representation of a kernel-density
2654- estimate using Gaussian kernels. This is the function used
2655- internally to estimate the PDF.
2656- DataFrame.plot.kde : Generate a KDE plot for a DataFrame.
2657-
2658- Examples
2659- --------
2663+ @Appender (_kde_docstring % {
2664+ 'this-datatype' : 'Series' ,
2665+ 'sibling-datatype' : 'DataFrame' ,
2666+ 'examples' : """
26602667 Given a Series of points randomly sampled from an unknown
26612668 distribution, estimate its distribution using KDE with automatic
26622669 bandwidth determination and plot the results, evaluating them at
@@ -2689,7 +2696,9 @@ def kde(self, bw_method=None, ind=None, **kwds):
26892696 :context: close-figs
26902697
26912698 >>> ax = s.plot.kde(ind=[1, 2, 3, 4, 5])
2692- """
2699+ """ .strip ()
2700+ })
2701+ def kde (self , bw_method = None , ind = None , ** kwds ):
26932702 return self (kind = 'kde' , bw_method = bw_method , ind = ind , ** kwds )
26942703
26952704 density = kde
@@ -2852,47 +2861,10 @@ def hist(self, by=None, bins=10, **kwds):
28522861 """
28532862 return self (kind = 'hist' , by = by , bins = bins , ** kwds )
28542863
2855- def kde (self , bw_method = None , ind = None , ** kwds ):
2856- """
2857- Generate Kernel Density Estimate plot using Gaussian kernels.
2858-
2859- In statistics, `kernel density estimation`_ (KDE) is a non-parametric
2860- way to estimate the probability density function (PDF) of a random
2861- variable. This function uses Gaussian kernels and includes automatic
2862- bandwith determination.
2863-
2864- .. _kernel density estimation:
2865- https://en.wikipedia.org/wiki/Kernel_density_estimation
2866-
2867- Parameters
2868- ----------
2869- bw_method : str, scalar or callable, optional
2870- The method used to calculate the estimator bandwidth. This can be
2871- 'scott', 'silverman', a scalar constant or a callable.
2872- If None (default), 'scott' is used.
2873- See :class:`scipy.stats.gaussian_kde` for more information.
2874- ind : NumPy array or integer, optional
2875- Evaluation points for the estimated PDF. If None (default),
2876- 1000 equally spaced points are used. If `ind` is a NumPy array, the
2877- KDE is evaluated at the points passed. If `ind` is an integer,
2878- `ind` number of equally spaced points are used.
2879- **kwds : optional
2880- Additional keyword arguments are documented in
2881- :meth:`pandas.DataFrame.plot`.
2882-
2883- Returns
2884- -------
2885- axes : matplotlib.AxesSubplot or np.array of them
2886-
2887- See Also
2888- --------
2889- scipy.stats.gaussian_kde : Representation of a kernel-density
2890- estimate using Gaussian kernels. This is the function used
2891- internally to estimate the PDF.
2892- Series.plot.kde : Generate a KDE plot for a Series.
2893-
2894- Examples
2895- --------
2864+ @Appender (_kde_docstring % {
2865+ 'this-datatype' : 'DataFrame' ,
2866+ 'sibling-datatype' : 'Series' ,
2867+ 'examples' : """
28962868 Given several Series of points randomly sampled from unknown
28972869 distributions, estimate their distribution using KDE with automatic
28982870 bandwidth determination and plot the results, evaluating them at
@@ -2928,7 +2900,9 @@ def kde(self, bw_method=None, ind=None, **kwds):
29282900 :context: close-figs
29292901
29302902 >>> ax = df.plot.kde(ind=[1, 2, 3, 4, 5, 6])
2931- """
2903+ """ .strip ()
2904+ })
2905+ def kde (self , bw_method = None , ind = None , ** kwds ):
29322906 return self (kind = 'kde' , bw_method = bw_method , ind = ind , ** kwds )
29332907
29342908 density = kde
0 commit comments