From f49d075b98bc21eae45cf6fca0531a8abcbacd1d Mon Sep 17 00:00:00 2001 From: pascal-schetelat Date: Wed, 19 Mar 2014 09:45:07 +0100 Subject: [PATCH] Add layout support similar to the hist plot layout Add an optional layout keyword argument in order to set the subplots layout --- pandas/tools/plotting.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/pandas/tools/plotting.py b/pandas/tools/plotting.py index 507e0127a5062..313418acceee0 100644 --- a/pandas/tools/plotting.py +++ b/pandas/tools/plotting.py @@ -793,7 +793,7 @@ def __init__(self, data, kind=None, by=None, subplots=False, sharex=True, ax=None, fig=None, title=None, xlim=None, ylim=None, xticks=None, yticks=None, sort_columns=False, fontsize=None, - secondary_y=False, colormap=None, **kwds): + secondary_y=False, colormap=None,layout=None,**kwds): self.data = data self.by = by @@ -803,6 +803,7 @@ def __init__(self, data, kind=None, by=None, subplots=False, sharex=True, self.sort_columns = sort_columns self.subplots = subplots + self.layout = layout self.sharex = sharex self.sharey = sharey self.figsize = figsize @@ -985,7 +986,18 @@ def _setup_subplots(self): self.axes = axes def _get_layout(self): - return (len(self.data.columns), 1) + n = len(self.data.columns) + if self.layout is not None: + if not isinstance(self.layout, (tuple, list)) or len(self.layout) != 2: + raise ValueError('Layout must be a tuple of (rows, columns)') + + rows, cols = self.layout + if rows * cols < n: + raise ValueError('Layout of %sx%s is incompatible with %s columns' % (rows, cols, n)) + return self.layout + else : + return (n, 1) + def _compute_plot_data(self): numeric_data = self.data.convert_objects()._get_numeric_data()