Skip to content

Commit

Permalink
ENH: add KDE plot from #1059
Browse files Browse the repository at this point in the history
  • Loading branch information
wesm committed May 19, 2012
1 parent ad2ad47 commit 861ab90
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
3 changes: 3 additions & 0 deletions RELEASE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pandas 0.8.0
- Add keys() method to DataFrame
- Add flexible replace method for replacing potentially values to Series and
DataFrame (#929, #1241)
- Add 'kde' plot kind for Series/DataFrame.plot (#1059)

**Improvements to existing features**

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

**API Changes**

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

pandas 0.7.3
============
Expand Down
34 changes: 34 additions & 0 deletions pandas/tools/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,38 @@ def _get_xticks(self):

return x

class KdePlot(MPLPlot):
def __init__(self, data, **kwargs):
MPLPlot.__init__(self, data, **kwargs)

def _get_plot_function(self):
return self.plt.Axes.plot

def _make_plot(self):
plotf = self._get_plot_function()
for i, (label, y) in enumerate(self._iter_data()):
if self.subplots:
ax = self.axes[i]
style = 'k'
else:
style = '' # empty string ignored
ax = self.ax
if self.style:
style = self.style
gkde = stats.gaussian_kde(y)
sample_range = max(y) - min(y)
ind = np.linspace(min(y) - 0.5 * sample_range,
max(y) + 0.5 * sample_range, 1000)
ax.set_ylabel("Density")
plotf(ax, ind, gkde.evaluate(ind), style, label=label, **self.kwds)
ax.grid(self.grid)

def _post_plot_logic(self):
df = self.data

if self.subplots and self.legend:
self.axes[0].legend(loc='best')

class LinePlot(MPLPlot):

def __init__(self, data, **kwargs):
Expand Down Expand Up @@ -682,6 +714,8 @@ def plot_series(series, label=None, kind='line', use_index=True, rot=None,
klass = LinePlot
elif kind in ('bar', 'barh'):
klass = BarPlot
elif kind == 'kde':
klass = KdePlot

if ax is None:
ax = _gca()
Expand Down

0 comments on commit 861ab90

Please sign in to comment.