From 531b9e5afa8efa8252daf3d361b0a21a9ec7fd11 Mon Sep 17 00:00:00 2001 From: Morgan Stuart Date: Sat, 15 Jul 2017 13:59:41 -0400 Subject: [PATCH] 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