From 08f2e3bda4f745210d2005963a957f9eec576b77 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Wed, 19 Jul 2017 00:06:36 -0700 Subject: [PATCH 1/2] Define DataFrame plot methods in DataFrame instead of pinning them on at the bottom of the module. Tried doing this with Series last week and it caused a circular import problem. Hopefully cleaning this but of DataFrame up won't be as difficult --- pandas/core/frame.py | 45 ++++++++++++++++++++------------------------ 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 9a79ca1d4eab1..f3ec111c370a1 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -5651,12 +5651,32 @@ def isin(self, values): values).reshape(self.shape), self.index, self.columns) + # ---------------------------------------------------------------------- + # Add plotting methods to DataFrame + plot = base.AccessorProperty(gfx.FramePlotMethods, gfx.FramePlotMethods) + hist = gfx.hist_frame + + @Appender(_shared_docs['boxplot'] % _shared_doc_kwargs) + def boxplot(self, column=None, by=None, ax=None, fontsize=None, rot=0, + grid=True, figsize=None, layout=None, + return_type=None, **kwds): + from pandas.plotting._core import boxplot + import matplotlib.pyplot as plt + ax = boxplot(self, column=column, by=by, ax=ax, fontsize=fontsize, + grid=grid, rot=rot, figsize=figsize, layout=layout, + return_type=return_type, **kwds) + plt.draw_if_interactive() + return ax + DataFrame._setup_axes(['index', 'columns'], info_axis=1, stat_axis=0, axes_are_reversed=True, aliases={'rows': 0}) DataFrame._add_numeric_operations() DataFrame._add_series_or_dataframe_operations() +ops.add_flex_arithmetic_methods(DataFrame, **ops.frame_flex_funcs) +ops.add_special_arithmetic_methods(DataFrame, **ops.frame_special_funcs) + _EMPTY_SERIES = Series([]) @@ -6002,28 +6022,3 @@ def _from_nested_dict(data): def _put_str(s, space): return ('%s' % s)[:space].ljust(space) - - -# ---------------------------------------------------------------------- -# Add plotting methods to DataFrame -DataFrame.plot = base.AccessorProperty(gfx.FramePlotMethods, - gfx.FramePlotMethods) -DataFrame.hist = gfx.hist_frame - - -@Appender(_shared_docs['boxplot'] % _shared_doc_kwargs) -def boxplot(self, column=None, by=None, ax=None, fontsize=None, rot=0, - grid=True, figsize=None, layout=None, return_type=None, **kwds): - from pandas.plotting._core import boxplot - import matplotlib.pyplot as plt - ax = boxplot(self, column=column, by=by, ax=ax, fontsize=fontsize, - grid=grid, rot=rot, figsize=figsize, layout=layout, - return_type=return_type, **kwds) - plt.draw_if_interactive() - return ax - - -DataFrame.boxplot = boxplot - -ops.add_flex_arithmetic_methods(DataFrame, **ops.frame_flex_funcs) -ops.add_special_arithmetic_methods(DataFrame, **ops.frame_special_funcs) From f8f46fa75e1d0f42256be2896ac53dae9a006913 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Wed, 19 Jul 2017 11:12:20 -0700 Subject: [PATCH 2/2] Define boxplot as boxplot_frame in plotting._core; Request from jreback --- pandas/core/frame.py | 13 +------------ pandas/plotting/_core.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index f3ec111c370a1..0cd1c0e05ce21 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -5655,18 +5655,7 @@ def isin(self, values): # Add plotting methods to DataFrame plot = base.AccessorProperty(gfx.FramePlotMethods, gfx.FramePlotMethods) hist = gfx.hist_frame - - @Appender(_shared_docs['boxplot'] % _shared_doc_kwargs) - def boxplot(self, column=None, by=None, ax=None, fontsize=None, rot=0, - grid=True, figsize=None, layout=None, - return_type=None, **kwds): - from pandas.plotting._core import boxplot - import matplotlib.pyplot as plt - ax = boxplot(self, column=column, by=by, ax=ax, fontsize=fontsize, - grid=grid, rot=rot, figsize=figsize, layout=layout, - return_type=return_type, **kwds) - plt.draw_if_interactive() - return ax + boxplot = gfx.boxplot_frame DataFrame._setup_axes(['index', 'columns'], info_axis=1, stat_axis=0, diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index a623288efc1ae..de96d17da2a9f 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -2034,6 +2034,18 @@ def plot_group(keys, values, ax): return result +@Appender(_shared_docs['boxplot'] % _shared_doc_kwargs) +def boxplot_frame(self, column=None, by=None, ax=None, fontsize=None, rot=0, + grid=True, figsize=None, layout=None, + return_type=None, **kwds): + import matplotlib.pyplot as plt + ax = boxplot(self, column=column, by=by, ax=ax, fontsize=fontsize, + grid=grid, rot=rot, figsize=figsize, layout=layout, + return_type=return_type, **kwds) + plt.draw_if_interactive() + return ax + + def scatter_plot(data, x, y, by=None, ax=None, figsize=None, grid=False, **kwargs): """