@@ -338,6 +338,38 @@ def _get_xticks(self):
338
338
339
339
return x
340
340
341
+ class KdePlot (MPLPlot ):
342
+ def __init__ (self , data , ** kwargs ):
343
+ MPLPlot .__init__ (self , data , ** kwargs )
344
+
345
+ def _get_plot_function (self ):
346
+ return self .plt .Axes .plot
347
+
348
+ def _make_plot (self ):
349
+ plotf = self ._get_plot_function ()
350
+ for i , (label , y ) in enumerate (self ._iter_data ()):
351
+ if self .subplots :
352
+ ax = self .axes [i ]
353
+ style = 'k'
354
+ else :
355
+ style = '' # empty string ignored
356
+ ax = self .ax
357
+ if self .style :
358
+ style = self .style
359
+ gkde = stats .gaussian_kde (y )
360
+ sample_range = max (y ) - min (y )
361
+ ind = np .linspace (min (y ) - 0.5 * sample_range ,
362
+ max (y ) + 0.5 * sample_range , 1000 )
363
+ ax .set_ylabel ("Density" )
364
+ plotf (ax , ind , gkde .evaluate (ind ), style , label = label , ** self .kwds )
365
+ ax .grid (self .grid )
366
+
367
+ def _post_plot_logic (self ):
368
+ df = self .data
369
+
370
+ if self .subplots and self .legend :
371
+ self .axes [0 ].legend (loc = 'best' )
372
+
341
373
class LinePlot (MPLPlot ):
342
374
343
375
def __init__ (self , data , ** kwargs ):
@@ -682,6 +714,8 @@ def plot_series(series, label=None, kind='line', use_index=True, rot=None,
682
714
klass = LinePlot
683
715
elif kind in ('bar' , 'barh' ):
684
716
klass = BarPlot
717
+ elif kind == 'kde' :
718
+ klass = KdePlot
685
719
686
720
if ax is None :
687
721
ax = _gca ()
0 commit comments