Skip to content

Backport PR #25586 on branch 0.24.x (BUG: secondary y axis could not be set to log scale (#25545)) #25599

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.24.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Bug Fixes

**Visualization**

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

Expand Down
3 changes: 3 additions & 0 deletions pandas/plotting/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
12 changes: 12 additions & 0 deletions pandas/tests/plotting/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down