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