Skip to content

Commit 8ce369a

Browse files
committed
ENH: use DataFrame columns name for legend title in plotting code, add marker option to scatter_matrix
1 parent f826c0e commit 8ce369a

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

pandas/tools/plotting.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from pandas.tseries.offsets import DateOffset
1313

1414
def scatter_matrix(frame, alpha=0.5, figsize=None, ax=None, grid=False,
15-
diagonal='hist', **kwds):
15+
diagonal='hist', marker='.', **kwds):
1616
"""
1717
Draw a matrix of scatter plots.
1818
@@ -54,7 +54,8 @@ def scatter_matrix(frame, alpha=0.5, figsize=None, ax=None, grid=False,
5454
ind = np.linspace(min(y), max(y), 1000)
5555
axes[i, j].plot(ind, gkde.evaluate(ind), **kwds)
5656
else:
57-
axes[i, j].scatter(df[b], df[a], alpha=alpha, **kwds)
57+
axes[i, j].scatter(df[b], df[a], marker=marker, alpha=alpha,
58+
**kwds)
5859

5960
axes[i, j].set_xlabel('')
6061
axes[i, j].set_ylabel('')
@@ -295,7 +296,7 @@ def _adorn_subplots(self):
295296
ax.grid(self.grid)
296297

297298
if self.legend and not self.subplots:
298-
self.ax.legend(loc='best')
299+
self.ax.legend(loc='best', title=self.legend_title)
299300

300301
if self.title:
301302
if self.subplots:
@@ -309,6 +310,14 @@ def _adorn_subplots(self):
309310
# ax_.set_xticks(self.xticks)
310311
ax_.set_xticklabels(xticklabels, rotation=self.rot)
311312

313+
@property
314+
def legend_title(self):
315+
if hasattr(self.data, 'columns'):
316+
stringified = map(str, self.data.columns.names)
317+
return ','.join(stringified)
318+
else:
319+
return None
320+
312321
@cache_readonly
313322
def plt(self):
314323
import matplotlib.pyplot as plt
@@ -565,7 +574,8 @@ def _make_plot(self):
565574
# loc=2, borderaxespad=0.)
566575
# self.fig.subplots_adjust(right=0.80)
567576

568-
ax.legend(patches, labels, loc='best')
577+
ax.legend(patches, labels, loc='best',
578+
title=self.legend_title)
569579

570580
self.fig.subplots_adjust(top=0.8, wspace=0, hspace=0)
571581

0 commit comments

Comments
 (0)