@@ -1380,6 +1380,51 @@ def orientation(self):
1380
1380
return 'vertical'
1381
1381
1382
1382
1383
+ _kde_docstring = \
1384
+ """
1385
+ Generate Kernel Density Estimate plot using Gaussian kernels.
1386
+
1387
+ In statistics, `kernel density estimation`_ (KDE) is a non-parametric
1388
+ way to estimate the probability density function (PDF) of a random
1389
+ variable. This function uses Gaussian kernels and includes automatic
1390
+ bandwith determination.
1391
+
1392
+ .. _kernel density estimation:
1393
+ https://en.wikipedia.org/wiki/Kernel_density_estimation
1394
+
1395
+ Parameters
1396
+ ----------
1397
+ bw_method : str, scalar or callable, optional
1398
+ The method used to calculate the estimator bandwidth. This can be
1399
+ 'scott', 'silverman', a scalar constant or a callable.
1400
+ If None (default), 'scott' is used.
1401
+ See :class:`scipy.stats.gaussian_kde` for more information.
1402
+ ind : NumPy array or integer, optional
1403
+ Evaluation points for the estimated PDF. If None (default),
1404
+ 1000 equally spaced points are used. If `ind` is a NumPy array, the
1405
+ KDE is evaluated at the points passed. If `ind` is an integer,
1406
+ `ind` number of equally spaced points are used.
1407
+ **kwds : optional
1408
+ Additional keyword arguments are documented in
1409
+ :meth:`pandas.%(this-datatype)s.plot`.
1410
+
1411
+ Returns
1412
+ -------
1413
+ axes : matplotlib.AxesSubplot or np.array of them
1414
+
1415
+ See Also
1416
+ --------
1417
+ scipy.stats.gaussian_kde : Representation of a kernel-density
1418
+ estimate using Gaussian kernels. This is the function used
1419
+ internally to estimate the PDF.
1420
+ %(sibling-datatype)s.plot.kde : Generate a KDE plot for a
1421
+ %(sibling-datatype)s.
1422
+
1423
+ Examples
1424
+ --------
1425
+ %(examples)s
1426
+ """
1427
+
1383
1428
class KdePlot (HistPlot ):
1384
1429
_kind = 'kde'
1385
1430
orientation = 'vertical'
@@ -2616,47 +2661,11 @@ def hist(self, bins=10, **kwds):
2616
2661
"""
2617
2662
return self (kind = 'hist' , bins = bins , ** kwds )
2618
2663
2619
- def kde (self , bw_method = None , ind = None , ** kwds ):
2664
+ @Appender (_kde_docstring % {
2665
+ 'this-datatype' : 'Series' ,
2666
+ 'sibling-datatype' : 'DataFrame' ,
2667
+ 'examples' :
2620
2668
"""
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
- --------
2660
2669
Given a Series of points randomly sampled from an unknown
2661
2670
distribution, estimate its distribution using KDE with automatic
2662
2671
bandwidth determination and plot the results, evaluating them at
@@ -2689,7 +2698,9 @@ def kde(self, bw_method=None, ind=None, **kwds):
2689
2698
:context: close-figs
2690
2699
2691
2700
>>> ax = s.plot.kde(ind=[1, 2, 3, 4, 5])
2692
- """
2701
+ """ .strip ()
2702
+ })
2703
+ def kde (self , bw_method = None , ind = None , ** kwds ):
2693
2704
return self (kind = 'kde' , bw_method = bw_method , ind = ind , ** kwds )
2694
2705
2695
2706
density = kde
@@ -2852,47 +2863,11 @@ def hist(self, by=None, bins=10, **kwds):
2852
2863
"""
2853
2864
return self (kind = 'hist' , by = by , bins = bins , ** kwds )
2854
2865
2855
- def kde (self , bw_method = None , ind = None , ** kwds ):
2866
+ @Appender (_kde_docstring % {
2867
+ 'this-datatype' : 'DataFrame' ,
2868
+ 'sibling-datatype' : 'Series' ,
2869
+ 'examples' :
2856
2870
"""
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
- --------
2896
2871
Given several Series of points randomly sampled from unknown
2897
2872
distributions, estimate their distribution using KDE with automatic
2898
2873
bandwidth determination and plot the results, evaluating them at
@@ -2928,7 +2903,9 @@ def kde(self, bw_method=None, ind=None, **kwds):
2928
2903
:context: close-figs
2929
2904
2930
2905
>>> ax = df.plot.kde(ind=[1, 2, 3, 4, 5, 6])
2931
- """
2906
+ """ .strip ()
2907
+ })
2908
+ def kde (self , bw_method = None , ind = None , ** kwds ):
2932
2909
return self (kind = 'kde' , bw_method = bw_method , ind = ind , ** kwds )
2933
2910
2934
2911
density = kde
0 commit comments