Skip to content

Commit f98033b

Browse files
committed
BUG: Fixes pandas-dev#36918 boxplots with matplotlib
1 parent 9c202a1 commit f98033b

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

pandas/plotting/_matplotlib/boxplot.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ def boxplot(
246246
):
247247

248248
import matplotlib.pyplot as plt
249+
from matplotlib.ticker import FixedFormatter
249250

250251
# validate return_type:
251252
if return_type not in BoxPlot._valid_return_types:
@@ -302,15 +303,13 @@ def plot_group(keys, values, ax: "Axes"):
302303
bp = ax.boxplot(values, **kwds)
303304
if fontsize is not None:
304305
ax.tick_params(axis="both", labelsize=fontsize)
306+
305307
if kwds.get("vert", 1):
306-
ticks = ax.get_xticks()
307-
if len(ticks) != len(keys):
308-
i, remainder = divmod(len(ticks), len(keys))
309-
assert remainder == 0, remainder
310-
keys *= i
311-
ax.set_xticklabels(keys, rotation=rot)
308+
axis = ax.xaxis
312309
else:
313-
ax.set_yticklabels(keys, rotation=rot)
310+
axis = ax.yaxis
311+
axis.set_major_formatter(FixedFormatter(keys))
312+
ax.tick_params(axis=axis.axis_name, which="major", rotation=rot)
314313
maybe_color_bp(bp, **kwds)
315314

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

0 commit comments

Comments
 (0)