Skip to content

Commit

Permalink
BUG: Set secondary axis font size for secondary_y during plotting
Browse files Browse the repository at this point in the history
The parameter was not being respected for `secondary_y`.

Closes pandas-devgh-12565
  • Loading branch information
Morgan243 authored and alanbato committed Nov 10, 2017
1 parent 4670153 commit b894fe3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.21.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ I/O

Plotting
^^^^^^^^

- Bug in plotting methods using ``secondary_y`` and ``fontsize`` not setting secondary axis font size (:issue:`12565`)


Groupby/Resample/Rolling
Expand Down
9 changes: 9 additions & 0 deletions pandas/plotting/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,13 +379,22 @@ def _post_plot_logic_common(self, ax, data):
self._apply_axis_properties(ax.xaxis, rot=self.rot,
fontsize=self.fontsize)
self._apply_axis_properties(ax.yaxis, fontsize=self.fontsize)

if hasattr(ax, 'right_ax'):
self._apply_axis_properties(ax.right_ax.yaxis,
fontsize=self.fontsize)

elif self.orientation == 'horizontal':
if self._need_to_set_index:
yticklabels = [labels.get(y, '') for y in ax.get_yticks()]
ax.set_yticklabels(yticklabels)
self._apply_axis_properties(ax.yaxis, rot=self.rot,
fontsize=self.fontsize)
self._apply_axis_properties(ax.xaxis, fontsize=self.fontsize)

if hasattr(ax, 'right_ax'):
self._apply_axis_properties(ax.right_ax.yaxis,
fontsize=self.fontsize)
else: # pragma no cover
raise ValueError

Expand Down
17 changes: 17 additions & 0 deletions pandas/tests/plotting/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2733,6 +2733,23 @@ def test_rcParams_bar_colors(self):
barplot = pd.DataFrame([[1, 2, 3]]).plot(kind="bar")
assert color_tuples == [c.get_facecolor() for c in barplot.patches]

@pytest.mark.parametrize('method', ['line', 'barh', 'bar'])
def test_secondary_axis_font_size(self, method):
# GH: 12565
df = (pd.DataFrame(np.random.randn(15, 2),
columns=list('AB'))
.assign(C=lambda df: df.B.cumsum())
.assign(D=lambda df: df.C * 1.1))

fontsize = 20
sy = ['C', 'D']

kwargs = dict(secondary_y=sy, fontsize=fontsize,
mark_right=True)
ax = getattr(df.plot, method)(**kwargs)
self._check_ticks_props(axes=ax.right_ax,
ylabelsize=fontsize)


def _generate_4_axes_via_gridspec():
import matplotlib.pyplot as plt
Expand Down

0 comments on commit b894fe3

Please sign in to comment.