Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH GH11978 access pd.plotting._misc from plot accessor #23811

Merged
merged 6 commits into from
Dec 23, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.24.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you list the plots that are now available instead of just saying many plots?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


.. _whatsnew_0240.api_breaking:

Expand Down
23 changes: 23 additions & 0 deletions pandas/plotting/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
16 changes: 16 additions & 0 deletions pandas/tests/plotting/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions pandas/tests/plotting/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -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