From d410a63be12524eaa5763db4862b99b482723d74 Mon Sep 17 00:00:00 2001 From: Johan von Forstner Date: Thu, 7 Mar 2019 10:37:24 +0100 Subject: [PATCH] BUG: secondary y axis could not be set to log scale (#25545) --- doc/source/whatsnew/v0.24.2.rst | 2 +- pandas/plotting/_core.py | 3 +++ pandas/tests/plotting/test_series.py | 12 ++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.24.2.rst b/doc/source/whatsnew/v0.24.2.rst index f864fcd04e3d4..9b5410a30dd50 100644 --- a/doc/source/whatsnew/v0.24.2.rst +++ b/doc/source/whatsnew/v0.24.2.rst @@ -90,7 +90,7 @@ Bug Fixes **Visualization** -- +- Bug in :meth:`Series.plot` where a secondary y axis could not be set to log scale (:issue:`25545`) - - diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index 48d870bfc2e03..0ea92a57ac3f8 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -287,6 +287,9 @@ def _maybe_right_yaxis(self, ax, axes_num): if not self._has_plotted_object(orig_ax): # no data on left y orig_ax.get_yaxis().set_visible(False) + + if self.logy or self.loglog: + new_ax.set_yscale('log') return new_ax def _setup_subplots(self): diff --git a/pandas/tests/plotting/test_series.py b/pandas/tests/plotting/test_series.py index 07a4b168a66f1..a234ea8f9416b 100644 --- a/pandas/tests/plotting/test_series.py +++ b/pandas/tests/plotting/test_series.py @@ -570,6 +570,18 @@ def test_df_series_secondary_legend(self): assert ax.get_yaxis().get_visible() tm.close() + @pytest.mark.slow + def test_secondary_logy(self): + # GH 25545 + s1 = Series(np.random.randn(30)) + s2 = Series(np.random.randn(30)) + + ax1 = s1.plot(logy=True) + ax2 = s2.plot(secondary_y=True, logy=True) + + assert ax1.get_yscale() == 'log' + assert ax2.get_yscale() == 'log' + @pytest.mark.slow def test_plot_fails_with_dupe_color_and_style(self): x = Series(randn(2))