Skip to content

BUG: Set y-axis label, limits and ticks for a secondary y-axis (#47753) #47754

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
merged 1 commit into from
Jul 18, 2022
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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.5.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,7 @@ Plotting
- The function :meth:`DataFrame.plot.scatter` now accepts ``color`` as an alias for ``c`` and ``size`` as an alias for ``s`` for consistency to other plotting functions (:issue:`44670`)
- Fix showing "None" as ylabel in :meth:`Series.plot` when not setting ylabel (:issue:`46129`)
- Bug in :meth:`DataFrame.plot` that led to xticks and vertical grids being improperly placed when plotting a quarterly series (:issue:`47602`)
- Bug in :meth:`DataFrame.plot` that prevented setting y-axis label, limits and ticks for a secondary y-axis (:issue:`47753`)

Groupby/resample/rolling
^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
1 change: 1 addition & 0 deletions pandas/plotting/_matplotlib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,7 @@ def _adorn_subplots(self):
)

for ax in self.axes:
ax = getattr(ax, "right_ax", ax)
if self.yticks is not None:
ax.set_yticks(self.yticks)

Expand Down
11 changes: 11 additions & 0 deletions pandas/tests/plotting/frame/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2204,6 +2204,17 @@ def test_xlabel_ylabel_dataframe_plane_plot(self, kind, xlabel, ylabel):
assert ax.get_xlabel() == (xcol if xlabel is None else xlabel)
assert ax.get_ylabel() == (ycol if ylabel is None else ylabel)

@pytest.mark.parametrize("secondary_y", (False, True))
def test_secondary_y(self, secondary_y):
ax_df = DataFrame([0]).plot(
secondary_y=secondary_y, ylabel="Y", ylim=(0, 100), yticks=[99]
)
for ax in ax_df.figure.axes:
if ax.yaxis.get_visible():
assert ax.get_ylabel() == "Y"
assert ax.get_ylim() == (0, 100)
assert ax.get_yticks()[0] == 99


def _generate_4_axes_via_gridspec():
import matplotlib as mpl
Expand Down