From 531b9e5afa8efa8252daf3d361b0a21a9ec7fd11 Mon Sep 17 00:00:00 2001 From: Morgan Stuart Date: Sat, 15 Jul 2017 13:59:41 -0400 Subject: [PATCH 1/4] Fix for Issue #12565 - font size on secondary_y There may be other plotting methods that need testing. --- doc/source/whatsnew/v0.21.0.txt | 2 +- pandas/plotting/_core.py | 9 +++++++++ pandas/tests/plotting/test_frame.py | 16 ++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.21.0.txt b/doc/source/whatsnew/v0.21.0.txt index bd19d71182762..483ce2232976f 100644 --- a/doc/source/whatsnew/v0.21.0.txt +++ b/doc/source/whatsnew/v0.21.0.txt @@ -166,7 +166,7 @@ I/O Plotting ^^^^^^^^ - +- Bug in plotting methods using ``secondary_y`` and ``fontsize`` not setting secondary axes font size (:issue:`12565`) Groupby/Resample/Rolling diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index f8e83aea03594..0fa2b6b79da75 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -379,6 +379,11 @@ def _post_plot_logic_common(self, ax, data): self._apply_axis_properties(ax.xaxis, rot=self.rot, fontsize=self.fontsize) self._apply_axis_properties(ax.yaxis, fontsize=self.fontsize) + + if hasattr(ax, 'right_ax'): + self._apply_axis_properties(ax.right_ax.yaxis, + fontsize=self.fontsize) + elif self.orientation == 'horizontal': if self._need_to_set_index: yticklabels = [labels.get(y, '') for y in ax.get_yticks()] @@ -386,6 +391,10 @@ def _post_plot_logic_common(self, ax, data): self._apply_axis_properties(ax.yaxis, rot=self.rot, fontsize=self.fontsize) self._apply_axis_properties(ax.xaxis, fontsize=self.fontsize) + + if hasattr(ax, 'right_ax'): + self._apply_axis_properties(ax.right_ax.yaxis, + fontsize=self.fontsize) else: # pragma no cover raise ValueError diff --git a/pandas/tests/plotting/test_frame.py b/pandas/tests/plotting/test_frame.py index 7878740f64e55..22307b37ffd36 100644 --- a/pandas/tests/plotting/test_frame.py +++ b/pandas/tests/plotting/test_frame.py @@ -2733,6 +2733,22 @@ def test_rcParams_bar_colors(self): barplot = pd.DataFrame([[1, 2, 3]]).plot(kind="bar") assert color_tuples == [c.get_facecolor() for c in barplot.patches] + @pytest.mark.parametrize('method', ['line', 'barh', 'bar']) + def test_secondary_axis_font_size(self, method): + df = (pd.DataFrame(np.random.randn(15, 2), + columns=list('AB')) + .assign(C=lambda df: df.B.cumsum()) + .assign(D=lambda df: df.C*1.1)) + + fontsize = 20 + sy = ['C', 'D'] + + kwargs = dict(secondary_y=sy, fontsize=fontsize, + mark_right=True) + ax = getattr(df.plot, method)(**kwargs) + self._check_ticks_props(axes=ax.right_ax, + ylabelsize=fontsize) + def _generate_4_axes_via_gridspec(): import matplotlib.pyplot as plt From 9e06e9b34f436bcc3f0f783094fd9a23cb08ee6d Mon Sep 17 00:00:00 2001 From: Morgan Stuart Date: Sat, 15 Jul 2017 15:09:32 -0400 Subject: [PATCH 2/4] Added GitHub issue number comment to unittest --- pandas/tests/plotting/test_frame.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/tests/plotting/test_frame.py b/pandas/tests/plotting/test_frame.py index 22307b37ffd36..726a115fb1bfe 100644 --- a/pandas/tests/plotting/test_frame.py +++ b/pandas/tests/plotting/test_frame.py @@ -2735,6 +2735,7 @@ def test_rcParams_bar_colors(self): @pytest.mark.parametrize('method', ['line', 'barh', 'bar']) def test_secondary_axis_font_size(self, method): + # GH: 12565 df = (pd.DataFrame(np.random.randn(15, 2), columns=list('AB')) .assign(C=lambda df: df.B.cumsum()) From 6510d2692802193826899b0dc44b002036fbfda9 Mon Sep 17 00:00:00 2001 From: Morgan Stuart Date: Sat, 15 Jul 2017 16:08:13 -0400 Subject: [PATCH 3/4] Axes -> axis in whatsnew change --- doc/source/whatsnew/v0.21.0.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.21.0.txt b/doc/source/whatsnew/v0.21.0.txt index 483ce2232976f..8d5b390801318 100644 --- a/doc/source/whatsnew/v0.21.0.txt +++ b/doc/source/whatsnew/v0.21.0.txt @@ -166,7 +166,7 @@ I/O Plotting ^^^^^^^^ -- Bug in plotting methods using ``secondary_y`` and ``fontsize`` not setting secondary axes font size (:issue:`12565`) +- Bug in plotting methods using ``secondary_y`` and ``fontsize`` not setting secondary axis font size (:issue:`12565`) Groupby/Resample/Rolling From 4642a2d2c5f3e84765c3c7dd3aec57f771ac9ba8 Mon Sep 17 00:00:00 2001 From: Morgan Stuart Date: Sat, 15 Jul 2017 16:24:48 -0400 Subject: [PATCH 4/4] Adding whitespace around arithmetic operator --- pandas/tests/plotting/test_frame.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/plotting/test_frame.py b/pandas/tests/plotting/test_frame.py index 726a115fb1bfe..6d813ac76cc4e 100644 --- a/pandas/tests/plotting/test_frame.py +++ b/pandas/tests/plotting/test_frame.py @@ -2739,7 +2739,7 @@ def test_secondary_axis_font_size(self, method): df = (pd.DataFrame(np.random.randn(15, 2), columns=list('AB')) .assign(C=lambda df: df.B.cumsum()) - .assign(D=lambda df: df.C*1.1)) + .assign(D=lambda df: df.C * 1.1)) fontsize = 20 sy = ['C', 'D']