Skip to content

Commit a3d10ba

Browse files
author
Chang She
committed
ENH: alias density to kde in plot methods pandas-dev#1343
1 parent 4e6a055 commit a3d10ba

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

pandas/tests/test_graphics.py

+2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def test_hist(self):
5959
@slow
6060
def test_kde(self):
6161
_check_plot_works(self.ts.plot, kind='kde')
62+
_check_plot_works(self.ts.plot, kind='density')
6263
ax = self.ts.plot(kind='kde', logy=True)
6364
self.assert_(ax.get_yscale() == 'log')
6465

@@ -229,6 +230,7 @@ def scat(**kwds):
229230
_check_plot_works(scat, marker='+')
230231
_check_plot_works(scat, vmin=0)
231232
_check_plot_works(scat, diagonal='kde')
233+
_check_plot_works(scat, diagonal='density')
232234
_check_plot_works(scat, diagonal='hist')
233235

234236
def scat2(x, y, by=None, ax=None, figsize=None):

pandas/tools/plotting.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
from pandas.tseries.period import PeriodIndex
1414
from pandas.tseries.offsets import DateOffset
1515

16+
def _get_standard_kind(kind):
17+
return {'density' : 'kde'}.get(kind, kind)
18+
1619

1720
def scatter_matrix(frame, alpha=0.5, figsize=None, ax=None, grid=False,
1821
diagonal='hist', marker='.', **kwds):
@@ -54,7 +57,7 @@ def scatter_matrix(frame, alpha=0.5, figsize=None, ax=None, grid=False,
5457
# Deal with the diagonal by drawing a histogram there.
5558
if diagonal == 'hist':
5659
axes[i, j].hist(values)
57-
elif diagonal == 'kde':
60+
elif diagonal in ('kde', 'density'):
5861
from scipy.stats import gaussian_kde
5962
y = values
6063
gkde = gaussian_kde(y)
@@ -673,7 +676,7 @@ def plot_frame(frame=None, subplots=False, sharex=True, sharey=False,
673676
-------
674677
ax_or_axes : matplotlib.AxesSubplot or list of them
675678
"""
676-
kind = kind.lower().strip()
679+
kind = _get_standard_kind(kind.lower().strip())
677680
if kind == 'line':
678681
klass = LinePlot
679682
elif kind in ('bar', 'barh'):
@@ -738,6 +741,7 @@ def plot_series(series, label=None, kind='line', use_index=True, rot=None,
738741
-----
739742
See matplotlib documentation online for more on this subject
740743
"""
744+
kind = _get_standard_kind(kind.lower().strip())
741745
if kind == 'line':
742746
klass = LinePlot
743747
elif kind in ('bar', 'barh'):

0 commit comments

Comments
 (0)