Skip to content

Commit 3f9bff6

Browse files
committed
ENH: add NA handling to scatter_matrix, close #1297
1 parent a53cfa9 commit 3f9bff6

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

pandas/tools/plotting.py

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

16+
1617
def scatter_matrix(frame, alpha=0.5, figsize=None, ax=None, grid=False,
1718
diagonal='hist', marker='.', **kwds):
1819
"""
@@ -43,21 +44,27 @@ def scatter_matrix(frame, alpha=0.5, figsize=None, ax=None, grid=False,
4344
# no gaps between subplots
4445
fig.subplots_adjust(wspace=0, hspace=0)
4546

47+
mask = com.notnull(df)
48+
4649
for i, a in zip(range(n), df.columns):
4750
for j, b in zip(range(n), df.columns):
4851
if i == j:
52+
values = df[a].values[mask[a].values]
53+
4954
# Deal with the diagonal by drawing a histogram there.
5055
if diagonal == 'hist':
51-
axes[i, j].hist(df[a])
56+
axes[i, j].hist(values)
5257
elif diagonal == 'kde':
5358
from scipy.stats import gaussian_kde
54-
y = df[a]
59+
y = values
5560
gkde = gaussian_kde(y)
56-
ind = np.linspace(min(y), max(y), 1000)
61+
ind = np.linspace(y.min(), y.max(), 1000)
5762
axes[i, j].plot(ind, gkde.evaluate(ind), **kwds)
5863
else:
59-
axes[i, j].scatter(df[b], df[a], marker=marker, alpha=alpha,
60-
**kwds)
64+
common = (mask[a] & mask[b]).values
65+
66+
axes[i, j].scatter(df[b][common], df[a][common],
67+
marker=marker, alpha=alpha, **kwds)
6168

6269
axes[i, j].set_xlabel('')
6370
axes[i, j].set_ylabel('')

0 commit comments

Comments
 (0)