40
40
from pandas ._typing import MatplotlibColor
41
41
42
42
43
+ def _set_ticklabels (ax : Axes , labels : list [str ], is_vertical : bool , ** kwargs ) -> None :
44
+ """Set the tick labels of a given axis.
45
+
46
+ Due to https://github.com/matplotlib/matplotlib/pull/17266, we need to handle the
47
+ case of repeated ticks (due to `FixedLocator`) and thus we duplicate the number of
48
+ labels.
49
+ """
50
+ ticks = ax .get_xticks () if is_vertical else ax .get_yticks ()
51
+ if len (ticks ) != len (labels ):
52
+ i , remainder = divmod (len (ticks ), len (labels ))
53
+ assert remainder == 0 , remainder
54
+ labels *= i
55
+ if is_vertical :
56
+ ax .set_xticklabels (labels , ** kwargs )
57
+ else :
58
+ ax .set_yticklabels (labels , ** kwargs )
59
+
60
+
43
61
class BoxPlot (LinePlot ):
44
62
@property
45
63
def _kind (self ) -> Literal ["box" ]:
@@ -193,7 +211,9 @@ def _make_plot(self) -> None:
193
211
)
194
212
self .maybe_color_bp (bp )
195
213
self ._return_obj [label ] = ret
196
- self ._set_ticklabels (ax , ticklabels )
214
+ _set_ticklabels (
215
+ ax = ax , labels = ticklabels , is_vertical = self .orientation == "vertical"
216
+ )
197
217
else :
198
218
y = self .data .values .T
199
219
ax = self ._get_ax (0 )
@@ -209,13 +229,9 @@ def _make_plot(self) -> None:
209
229
labels = [pprint_thing (left ) for left in labels ]
210
230
if not self .use_index :
211
231
labels = [pprint_thing (key ) for key in range (len (labels ))]
212
- self ._set_ticklabels (ax , labels )
213
-
214
- def _set_ticklabels (self , ax : Axes , labels : list [str ]) -> None :
215
- if self .orientation == "vertical" :
216
- ax .set_xticklabels (labels )
217
- else :
218
- ax .set_yticklabels (labels )
232
+ _set_ticklabels (
233
+ ax = ax , labels = labels , is_vertical = self .orientation == "vertical"
234
+ )
219
235
220
236
def _make_legend (self ) -> None :
221
237
pass
@@ -382,16 +398,9 @@ def plot_group(keys, values, ax: Axes, **kwds):
382
398
ax .tick_params (axis = "both" , labelsize = fontsize )
383
399
384
400
# GH 45465: x/y are flipped when "vert" changes
385
- is_vertical = kwds .get ("vert" , True )
386
- ticks = ax .get_xticks () if is_vertical else ax .get_yticks ()
387
- if len (ticks ) != len (keys ):
388
- i , remainder = divmod (len (ticks ), len (keys ))
389
- assert remainder == 0 , remainder
390
- keys *= i
391
- if is_vertical :
392
- ax .set_xticklabels (keys , rotation = rot )
393
- else :
394
- ax .set_yticklabels (keys , rotation = rot )
401
+ _set_ticklabels (
402
+ ax = ax , labels = keys , is_vertical = kwds .get ("vert" , True ), rotation = rot
403
+ )
395
404
maybe_color_bp (bp , ** kwds )
396
405
397
406
# Return axes in multiplot case, maybe revisit later # 985
0 commit comments