Skip to content

Commit bb53dae

Browse files
committed
BUG: secondary y axis could not be set to log scale (#25545)
1 parent 3e652ac commit bb53dae

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

doc/source/whatsnew/v0.24.2.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ Bug Fixes
9090

9191
**Visualization**
9292

93-
-
93+
- Bug in :meth:`Series.plot` where a secondary y axis could not be set to log scale (:issue:`25545`)
9494
-
9595
-
9696

pandas/plotting/_core.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,9 @@ def _maybe_right_yaxis(self, ax, axes_num):
287287

288288
if not self._has_plotted_object(orig_ax): # no data on left y
289289
orig_ax.get_yaxis().set_visible(False)
290+
291+
if self.logy or self.loglog:
292+
new_ax.set_yscale('log')
290293
return new_ax
291294

292295
def _setup_subplots(self):
@@ -613,7 +616,7 @@ def _get_index_name(self):
613616

614617
@classmethod
615618
def _get_ax_layer(cls, ax, primary=True):
616-
"""get left (primary) or right (secondary) axes"""
619+
"""get left (primary) or right () axes"""
617620
if primary:
618621
return getattr(ax, 'left_ax', ax)
619622
else:

pandas/tests/plotting/test_series.py

+12
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,18 @@ def test_df_series_secondary_legend(self):
570570
assert ax.get_yaxis().get_visible()
571571
tm.close()
572572

573+
@pytest.mark.slow
574+
def test_secondary_logy(self):
575+
# GH 25545
576+
s1 = Series(np.random.randn(30))
577+
s2 = Series(np.random.randn(30))
578+
579+
ax1 = s1.plot(logy=True)
580+
ax2 = s2.plot(secondary_y=True, logy=True)
581+
582+
assert ax1.get_yscale() == 'log'
583+
assert ax2.get_yscale() == 'log'
584+
573585
@pytest.mark.slow
574586
def test_plot_fails_with_dupe_color_and_style(self):
575587
x = Series(randn(2))

0 commit comments

Comments
 (0)