Skip to content

Commit e1f962f

Browse files
JustinZhengBCPingviinituutti
authored andcommitted
ENH GH11978 access pd.plotting._misc from plot accessor (pandas-dev#23811)
1 parent dd6c082 commit e1f962f

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

doc/source/whatsnew/v0.24.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ Other Enhancements
371371
- :meth:`MultiIndex.to_flat_index` has been added to flatten multiple levels into a single-level :class:`Index` object.
372372
- :meth:`DataFrame.to_stata` and :class:`pandas.io.stata.StataWriter117` can write mixed sting columns to Stata strl format (:issue:`23633`)
373373
- :meth:`DataFrame.between_time` and :meth:`DataFrame.at_time` have gained the an ``axis`` parameter (:issue:`8839`)
374+
- 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`)
374375
- :class:`IntervalIndex` has gained the :attr:`~IntervalIndex.is_overlapping` attribute to indicate if the ``IntervalIndex`` contains any overlapping intervals (:issue:`23309`)
375376

376377
.. _whatsnew_0240.api_breaking:

pandas/plotting/_core.py

+23
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from pandas.core.generic import _shared_doc_kwargs, _shared_docs
2727

2828
from pandas.io.formats.printing import pprint_thing
29+
from pandas.plotting import _misc as misc
2930
from pandas.plotting._compat import _mpl_ge_3_0_0
3031
from pandas.plotting._style import _get_standard_colors, plot_params
3132
from pandas.plotting._tools import (
@@ -2905,6 +2906,15 @@ def pie(self, **kwds):
29052906
"""
29062907
return self(kind='pie', **kwds)
29072908

2909+
def lag(self, *args, **kwds):
2910+
return misc.lag_plot(self._parent, *args, **kwds)
2911+
2912+
def autocorrelation(self, *args, **kwds):
2913+
return misc.autocorrelation_plot(self._parent, *args, **kwds)
2914+
2915+
def bootstrap(self, *args, **kwds):
2916+
return misc.bootstrap_plot(self._parent, *args, **kwds)
2917+
29082918

29092919
class FramePlotMethods(BasePlotMethods):
29102920
"""DataFrame plotting accessor and method
@@ -3600,3 +3610,16 @@ def hexbin(self, x, y, C=None, reduce_C_function=None, gridsize=None,
36003610
if gridsize is not None:
36013611
kwds['gridsize'] = gridsize
36023612
return self(kind='hexbin', x=x, y=y, C=C, **kwds)
3613+
3614+
def scatter_matrix(self, *args, **kwds):
3615+
return misc.scatter_matrix(self._parent, *args, **kwds)
3616+
3617+
def andrews_curves(self, class_column, *args, **kwds):
3618+
return misc.andrews_curves(self._parent, class_column, *args, **kwds)
3619+
3620+
def parallel_coordinates(self, class_column, *args, **kwds):
3621+
return misc.parallel_coordinates(self._parent, class_column,
3622+
*args, **kwds)
3623+
3624+
def radviz(self, class_column, *args, **kwds):
3625+
return misc.radviz(self._parent, class_column, *args, **kwds)

pandas/tests/plotting/test_frame.py

+16
Original file line numberDiff line numberDiff line change
@@ -2988,6 +2988,22 @@ def test_secondary_axis_font_size(self, method):
29882988
self._check_ticks_props(axes=ax.right_ax,
29892989
ylabelsize=fontsize)
29902990

2991+
def test_misc_bindings(self, mock):
2992+
df = pd.DataFrame(randn(10, 10), columns=list('abcdefghij'))
2993+
p1 = mock.patch('pandas.plotting._misc.scatter_matrix',
2994+
return_value=2)
2995+
p2 = mock.patch('pandas.plotting._misc.andrews_curves',
2996+
return_value=2)
2997+
p3 = mock.patch('pandas.plotting._misc.parallel_coordinates',
2998+
return_value=2)
2999+
p4 = mock.patch('pandas.plotting._misc.radviz',
3000+
return_value=2)
3001+
with p1, p2, p3, p4:
3002+
assert df.plot.scatter_matrix() == 2
3003+
assert df.plot.andrews_curves('a') == 2
3004+
assert df.plot.parallel_coordinates('a') == 2
3005+
assert df.plot.radviz('a') == 2
3006+
29913007

29923008
def _generate_4_axes_via_gridspec():
29933009
import matplotlib.pyplot as plt

pandas/tests/plotting/test_series.py

+13
Original file line numberDiff line numberDiff line change
@@ -877,3 +877,16 @@ def test_custom_business_day_freq(self):
877877
freq=CustomBusinessDay(holidays=['2014-05-26'])))
878878

879879
_check_plot_works(s.plot)
880+
881+
def test_misc_bindings(self, mock):
882+
s = Series(randn(10))
883+
p1 = mock.patch('pandas.plotting._misc.lag_plot',
884+
return_value=2)
885+
p2 = mock.patch('pandas.plotting._misc.autocorrelation_plot',
886+
return_value=2)
887+
p3 = mock.patch('pandas.plotting._misc.bootstrap_plot',
888+
return_value=2)
889+
with p1, p2, p3:
890+
assert s.plot.lag() == 2
891+
assert s.plot.autocorrelation() == 2
892+
assert s.plot.bootstrap() == 2

0 commit comments

Comments
 (0)