From 9583b6dd28f98a40a12185627ca2167a34ae4c21 Mon Sep 17 00:00:00 2001 From: JustinZhengBC Date: Mon, 19 Nov 2018 16:27:40 -0800 Subject: [PATCH 1/3] ENH-11978 access pd.plotting._misc from df.plot --- doc/source/whatsnew/v0.24.0.rst | 1 + pandas/plotting/_core.py | 23 +++++++++++++++++++++++ pandas/tests/plotting/test_frame.py | 16 ++++++++++++++++ pandas/tests/plotting/test_series.py | 13 +++++++++++++ 4 files changed, 53 insertions(+) diff --git a/doc/source/whatsnew/v0.24.0.rst b/doc/source/whatsnew/v0.24.0.rst index 7d8ee975ba02c..c121dba6a22cf 100644 --- a/doc/source/whatsnew/v0.24.0.rst +++ b/doc/source/whatsnew/v0.24.0.rst @@ -293,6 +293,7 @@ Other Enhancements - :meth:`MultiIndex.to_flat_index` has been added to flatten multiple levels into a single-level :class:`Index` object. - :meth:`DataFrame.to_stata` and :class:` pandas.io.stata.StataWriter117` can write mixed sting columns to Stata strl format (:issue:`23633`) - :meth:`DataFrame.between_time` and :meth:`DataFrame.at_time` have gained the an ``axis`` parameter (:issue: `8839`) +- many plots in the ``pandas.plotting`` module are now accessible from calling :meth:`DataFrame.plot` (:issue:`11978`) .. _whatsnew_0240.api_breaking: diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index 27f332ca50231..66b59a49c83eb 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -38,6 +38,7 @@ _handle_shared_axes, _get_all_lines, _get_xlim, _set_ticks_props, format_date_labels) +from pandas.plotting import _misc as misc try: from pandas.plotting import _converter @@ -2913,6 +2914,15 @@ def pie(self, **kwds): """ return self(kind='pie', **kwds) + def lag(self, *args, **kwds): + return misc.lag_plot(self._parent, *args, **kwds) + + def autocorrelation(self, *args, **kwds): + return misc.autocorrelation_plot(self._parent, *args, **kwds) + + def bootstrap(self, *args, **kwds): + return misc.bootstrap_plot(self._parent, *args, **kwds) + class FramePlotMethods(BasePlotMethods): """DataFrame plotting accessor and method @@ -3609,3 +3619,16 @@ def hexbin(self, x, y, C=None, reduce_C_function=None, gridsize=None, if gridsize is not None: kwds['gridsize'] = gridsize return self(kind='hexbin', x=x, y=y, C=C, **kwds) + + def scatter_matrix(self, *args, **kwds): + return misc.scatter_matrix(self._parent, *args, **kwds) + + def andrews_curves(self, class_column, *args, **kwds): + return misc.andrews_curves(self._parent, class_column, *args, **kwds) + + def parallel_coordinates(self, class_column, *args, **kwds): + return misc.parallel_coordinates(self._parent, class_column, + *args, **kwds) + + def radviz(self, class_column, *args, **kwds): + return misc.radviz(self._parent, class_column, *args, **kwds) diff --git a/pandas/tests/plotting/test_frame.py b/pandas/tests/plotting/test_frame.py index 25dfbaba762c9..5b9baa9ef0648 100644 --- a/pandas/tests/plotting/test_frame.py +++ b/pandas/tests/plotting/test_frame.py @@ -2993,6 +2993,22 @@ def test_secondary_axis_font_size(self, method): self._check_ticks_props(axes=ax.right_ax, ylabelsize=fontsize) + def test_misc_bindings(self, mock): + df = pd.DataFrame(randn(10, 10), columns=list('abcdefghij')) + p1 = mock.patch('pandas.plotting._misc.scatter_matrix', + return_value=2) + p2 = mock.patch('pandas.plotting._misc.andrews_curves', + return_value=2) + p3 = mock.patch('pandas.plotting._misc.parallel_coordinates', + return_value=2) + p4 = mock.patch('pandas.plotting._misc.radviz', + return_value=2) + with p1, p2, p3, p4: + assert df.plot.scatter_matrix() == 2 + assert df.plot.andrews_curves('a') == 2 + assert df.plot.parallel_coordinates('a') == 2 + assert df.plot.radviz('a') == 2 + def _generate_4_axes_via_gridspec(): import matplotlib.pyplot as plt diff --git a/pandas/tests/plotting/test_series.py b/pandas/tests/plotting/test_series.py index dc708278836d2..8fdd36c037d89 100644 --- a/pandas/tests/plotting/test_series.py +++ b/pandas/tests/plotting/test_series.py @@ -876,3 +876,16 @@ def test_custom_business_day_freq(self): freq=CustomBusinessDay(holidays=['2014-05-26']))) _check_plot_works(s.plot) + + def test_misc_bindings(self, mock): + s = Series(randn(10)) + p1 = mock.patch('pandas.plotting._misc.lag_plot', + return_value=2) + p2 = mock.patch('pandas.plotting._misc.autocorrelation_plot', + return_value=2) + p3 = mock.patch('pandas.plotting._misc.bootstrap_plot', + return_value=2) + with p1, p2, p3: + assert s.plot.lag() == 2 + assert s.plot.autocorrelation() == 2 + assert s.plot.bootstrap() == 2 From 9e1aa95f6c6d1f95cf57ede9f25d2665e1710d2e Mon Sep 17 00:00:00 2001 From: JustinZhengBC Date: Tue, 20 Nov 2018 21:42:44 -0800 Subject: [PATCH 2/3] ENH-11978 fix whatsnew --- doc/source/whatsnew/v0.24.0.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v0.24.0.rst b/doc/source/whatsnew/v0.24.0.rst index 2e710cdc4bb84..3194d8588a531 100644 --- a/doc/source/whatsnew/v0.24.0.rst +++ b/doc/source/whatsnew/v0.24.0.rst @@ -293,7 +293,7 @@ Other Enhancements - :meth:`MultiIndex.to_flat_index` has been added to flatten multiple levels into a single-level :class:`Index` object. - :meth:`DataFrame.to_stata` and :class:` pandas.io.stata.StataWriter117` can write mixed sting columns to Stata strl format (:issue:`23633`) - :meth:`DataFrame.between_time` and :meth:`DataFrame.at_time` have gained the an ``axis`` parameter (:issue: `8839`) -- many plots in the ``pandas.plotting`` module are now accessible from calling :meth:`DataFrame.plot` (:issue:`11978`) +- The ``scatter_matrix``, ``andrews_curves``, ``parallel_coordinates``, ``lag_plot``, ``autocorrelation_plot``, ``bootstrap_plot``, and ``radviz`` plots from the ``pandas.plotting`` module are now accessible from calling :meth:`DataFrame.plot` (:issue:`11978`) .. _whatsnew_0240.api_breaking: @@ -1486,4 +1486,3 @@ Contributors ~~~~~~~~~~~~ .. contributors:: v0.23.4..HEAD - From bdf1726c3e5f49582aabba219f4ba007e153ed52 Mon Sep 17 00:00:00 2001 From: JustinZhengBC Date: Wed, 12 Dec 2018 23:29:18 -0800 Subject: [PATCH 3/3] fix isort --- pandas/plotting/_core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index 313eba409e603..c55952085f8c5 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -26,12 +26,12 @@ from pandas.core.generic import _shared_doc_kwargs, _shared_docs from pandas.io.formats.printing import pprint_thing +from pandas.plotting import _misc as misc from pandas.plotting._compat import _mpl_ge_3_0_0 from pandas.plotting._style import _get_standard_colors, plot_params from pandas.plotting._tools import ( _flatten, _get_all_lines, _get_xlim, _handle_shared_axes, _set_ticks_props, _subplots, format_date_labels, table) -from pandas.plotting import _misc as misc try: from pandas.plotting import _converter