Skip to content

Commit b6c77ad

Browse files
johan12345MeeseeksDev[bot]
authored and
MeeseeksDev[bot]
committed
Backport PR pandas-dev#25586: BUG: secondary y axis could not be set to log scale (pandas-dev#25545)
1 parent 1577b0e commit b6c77ad

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

doc/source/whatsnew/v0.24.2.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ Bug Fixes
9292

9393
**Visualization**
9494

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

pandas/plotting/_core.py

+3
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):

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)