Skip to content

Commit 861ab90

Browse files
committed
ENH: add KDE plot from #1059
1 parent ad2ad47 commit 861ab90

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

RELEASE.rst

+3
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ pandas 0.8.0
5353
- Add keys() method to DataFrame
5454
- Add flexible replace method for replacing potentially values to Series and
5555
DataFrame (#929, #1241)
56+
- Add 'kde' plot kind for Series/DataFrame.plot (#1059)
5657

5758
**Improvements to existing features**
5859

@@ -70,6 +71,7 @@ pandas 0.8.0
7071
- Can pass multiple columns to GroupBy object, e.g. grouped[[col1, col2]] to
7172
only aggregate a subset of the value columns (#383)
7273
- Add histogram / kde plot options for scatter_matrix diagonals (#1237)
74+
- Add inplace option to DataFrame.drop_duplicates (#805)
7375

7476
**API Changes**
7577

@@ -101,6 +103,7 @@ pandas 0.8.0
101103
- Handle Excel 2003 #N/A as NaN from xlrd (#1213, #1225)
102104
- Fix timestamp locale-related deserialization issues with HDFStore by moving
103105
to datetime64 representation (#1081, #809)
106+
- Fix DataFrame.duplicated/drop_duplicates NA value handling (#557)
104107

105108
pandas 0.7.3
106109
============

pandas/tools/plotting.py

+34
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,38 @@ def _get_xticks(self):
338338

339339
return x
340340

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+
341373
class LinePlot(MPLPlot):
342374

343375
def __init__(self, data, **kwargs):
@@ -682,6 +714,8 @@ def plot_series(series, label=None, kind='line', use_index=True, rot=None,
682714
klass = LinePlot
683715
elif kind in ('bar', 'barh'):
684716
klass = BarPlot
717+
elif kind == 'kde':
718+
klass = KdePlot
685719

686720
if ax is None:
687721
ax = _gca()

0 commit comments

Comments
 (0)