Skip to content

Commit b342331

Browse files
cbrnrTomAugspurger
authored andcommitted
Apply fontsize to both x- and y-axis tick labels (pandas-dev#15161)
* Apply fontsize to both x- and y-axis tick labels * Add tests * Add note in whatsnew
1 parent 681e6a9 commit b342331

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

doc/source/whatsnew/v0.20.0.txt

+3
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,9 @@ Bug Fixes
439439
- Bug in ``pd.read_csv()`` for the C engine where ``usecols`` were being indexed incorrectly with ``parse_dates`` (:issue:`14792`)
440440

441441
- Bug in ``Series.dt.round`` inconsistent behaviour on NAT's with different arguments (:issue:`14940`)
442+
442443
- Bug in ``.read_json()`` for Python 2 where ``lines=True`` and contents contain non-ascii unicode characters (:issue:`15132`)
443444

444445
- Bug in ``pd.read_csv()`` with ``float_precision='round_trip'`` which caused a segfault when a text entry is parsed (:issue:`15140`)
446+
447+
- Bug in ``DataFrame.boxplot`` where ``fontsize`` was not applied to the tick labels on both axes (:issue:`15108`)

pandas/tests/plotting/test_boxplot_method.py

+10
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ def test_boxplot_empty_column(self):
158158
df.loc[:, 0] = np.nan
159159
_check_plot_works(df.boxplot, return_type='axes')
160160

161+
def test_fontsize(self):
162+
df = DataFrame({"a": [1, 2, 3, 4, 5, 6]})
163+
self._check_ticks_props(df.boxplot("a", fontsize=16),
164+
xlabelsize=16, ylabelsize=16)
165+
161166

162167
@tm.mplskip
163168
class TestDataFrameGroupByPlots(TestPlotBase):
@@ -369,6 +374,11 @@ def test_grouped_box_multiple_axes(self):
369374
with tm.assert_produces_warning(UserWarning):
370375
axes = df.groupby('classroom').boxplot(ax=axes)
371376

377+
def test_fontsize(self):
378+
df = DataFrame({"a": [1, 2, 3, 4, 5, 6], "b": [0, 0, 0, 1, 1, 1]})
379+
self._check_ticks_props(df.boxplot("a", by="b", fontsize=16),
380+
xlabelsize=16, ylabelsize=16)
381+
372382

373383
if __name__ == '__main__':
374384
nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'],

pandas/tools/plotting.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -2768,10 +2768,12 @@ def plot_group(keys, values, ax):
27682768
keys = [pprint_thing(x) for x in keys]
27692769
values = [remove_na(v) for v in values]
27702770
bp = ax.boxplot(values, **kwds)
2771+
if fontsize is not None:
2772+
ax.tick_params(axis='both', labelsize=fontsize)
27712773
if kwds.get('vert', 1):
2772-
ax.set_xticklabels(keys, rotation=rot, fontsize=fontsize)
2774+
ax.set_xticklabels(keys, rotation=rot)
27732775
else:
2774-
ax.set_yticklabels(keys, rotation=rot, fontsize=fontsize)
2776+
ax.set_yticklabels(keys, rotation=rot)
27752777
maybe_color_bp(bp)
27762778

27772779
# Return axes in multiplot case, maybe revisit later # 985

0 commit comments

Comments
 (0)