From 43d2c4f8c7c7f12fc012401fc52d1ae2fbe6a748 Mon Sep 17 00:00:00 2001 From: Souvik Mandal Date: Fri, 27 Dec 2019 00:50:33 +0530 Subject: [PATCH 1/6] BUG: Fix xrot=0 in DataFrame.hist for subplots --- pandas/plotting/_matplotlib/hist.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/plotting/_matplotlib/hist.py b/pandas/plotting/_matplotlib/hist.py index 8957389ac2b13..f8b2c7ab123d0 100644 --- a/pandas/plotting/_matplotlib/hist.py +++ b/pandas/plotting/_matplotlib/hist.py @@ -250,7 +250,8 @@ def _grouped_hist( def plot_group(group, ax): ax.hist(group.dropna().values, bins=bins, **kwargs) - xrot = xrot or rot + if xrot is None: + xrot = rot fig, axes = _grouped_plot( plot_group, From 8fd9d484f9500af22159af44c0b9ef10342e9919 Mon Sep 17 00:00:00 2001 From: Souvik Mandal Date: Fri, 27 Dec 2019 00:52:43 +0530 Subject: [PATCH 2/6] TST: test for #30288 --- pandas/tests/plotting/test_hist_method.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pandas/tests/plotting/test_hist_method.py b/pandas/tests/plotting/test_hist_method.py index 6c1c7dfd1a4a4..c1c0f7fd2532f 100644 --- a/pandas/tests/plotting/test_hist_method.py +++ b/pandas/tests/plotting/test_hist_method.py @@ -253,6 +253,20 @@ def test_tight_layout(self): tm.close() + def test_hist_subplot_xrot(self): + df = DataFrame({ + 'length': [1.5, 0.5, 1.2, 0.9, 3], + 'animal': ['pig', 'rabbit', 'pig', 'pig', 'rabbit'] + }) + axes = _check_plot_works( + df.hist, + filterwarnings="always", + column='length', + by='animal', + bins=5, + xrot=0 + ) + self._check_ticks_props(axes,xrot=0) @td.skip_if_no_mpl class TestDataFrameGroupByPlots(TestPlotBase): From abe14497a6a51a3e1307d0e896a6e2aa06880c44 Mon Sep 17 00:00:00 2001 From: Souvik Mandal Date: Fri, 27 Dec 2019 00:57:19 +0530 Subject: [PATCH 3/6] fix whitespace --- pandas/tests/plotting/test_hist_method.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/tests/plotting/test_hist_method.py b/pandas/tests/plotting/test_hist_method.py index c1c0f7fd2532f..0bc9ee68e4c41 100644 --- a/pandas/tests/plotting/test_hist_method.py +++ b/pandas/tests/plotting/test_hist_method.py @@ -266,7 +266,8 @@ def test_hist_subplot_xrot(self): bins=5, xrot=0 ) - self._check_ticks_props(axes,xrot=0) + self._check_ticks_props(axes, xrot=0) + @td.skip_if_no_mpl class TestDataFrameGroupByPlots(TestPlotBase): From 73fe3b9da56301e1405e763f5c7a455c4abe9576 Mon Sep 17 00:00:00 2001 From: Souvik Mandal Date: Fri, 27 Dec 2019 01:03:55 +0530 Subject: [PATCH 4/6] reformat file black pandas --- pandas/tests/plotting/test_hist_method.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/pandas/tests/plotting/test_hist_method.py b/pandas/tests/plotting/test_hist_method.py index 0bc9ee68e4c41..460c4f6e10902 100644 --- a/pandas/tests/plotting/test_hist_method.py +++ b/pandas/tests/plotting/test_hist_method.py @@ -254,17 +254,19 @@ def test_tight_layout(self): tm.close() def test_hist_subplot_xrot(self): - df = DataFrame({ - 'length': [1.5, 0.5, 1.2, 0.9, 3], - 'animal': ['pig', 'rabbit', 'pig', 'pig', 'rabbit'] - }) + df = DataFrame( + { + "length": [1.5, 0.5, 1.2, 0.9, 3], + "animal": ["pig", "rabbit", "pig", "pig", "rabbit"], + } + ) axes = _check_plot_works( df.hist, filterwarnings="always", - column='length', - by='animal', + column="length", + by="animal", bins=5, - xrot=0 + xrot=0, ) self._check_ticks_props(axes, xrot=0) From 3643aa10ab529c5f927744e3641085e972a71dea Mon Sep 17 00:00:00 2001 From: Souvik Mandal Date: Fri, 27 Dec 2019 20:59:19 +0530 Subject: [PATCH 5/6] add GH issue number to test --- pandas/tests/plotting/test_hist_method.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/tests/plotting/test_hist_method.py b/pandas/tests/plotting/test_hist_method.py index 460c4f6e10902..74d48c10ad9a0 100644 --- a/pandas/tests/plotting/test_hist_method.py +++ b/pandas/tests/plotting/test_hist_method.py @@ -254,6 +254,7 @@ def test_tight_layout(self): tm.close() def test_hist_subplot_xrot(self): + # GH 30288 df = DataFrame( { "length": [1.5, 0.5, 1.2, 0.9, 3], From a50f751c2985afa461889bc59056de64992061e3 Mon Sep 17 00:00:00 2001 From: Souvik Mandal Date: Fri, 27 Dec 2019 21:22:58 +0530 Subject: [PATCH 6/6] add whatsnew entry --- doc/source/whatsnew/v1.0.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index 852694a51e79d..2b45f8a8f0de2 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -828,6 +828,7 @@ Plotting - :func:`set_option` now validates that the plot backend provided to ``'plotting.backend'`` implements the backend when the option is set, rather than when a plot is created (:issue:`28163`) - :meth:`DataFrame.plot` now allow a ``backend`` keyword argument to allow changing between backends in one session (:issue:`28619`). - Bug in color validation incorrectly raising for non-color styles (:issue:`29122`). +- Bug in :meth:`DataFrame.hist`, ``xrot=0`` does not work with ``by`` and subplots (:issue:`30288`). Groupby/resample/rolling ^^^^^^^^^^^^^^^^^^^^^^^^