diff --git a/RELEASE.rst b/RELEASE.rst index cc86e644a0f38..515d9bab794ec 100644 --- a/RELEASE.rst +++ b/RELEASE.rst @@ -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** @@ -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** @@ -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 ============ diff --git a/pandas/tools/plotting.py b/pandas/tools/plotting.py index 11fc59add1eb9..9fd3e5d173bf9 100644 --- a/pandas/tools/plotting.py +++ b/pandas/tools/plotting.py @@ -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): @@ -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()