@@ -200,7 +200,11 @@ def _make_legend(self):
200
200
pass
201
201
202
202
def _post_plot_logic (self , ax , data ):
203
- pass
203
+ # GH 45465: make sure that the boxplot doesn't ignore xlabel/ylabel
204
+ if self .xlabel :
205
+ ax .set_xlabel (pprint_thing (self .xlabel ))
206
+ if self .ylabel :
207
+ ax .set_ylabel (pprint_thing (self .ylabel ))
204
208
205
209
@property
206
210
def orientation (self ):
@@ -237,20 +241,31 @@ def _grouped_plot_by_column(
237
241
columns = data ._get_numeric_data ().columns .difference (by )
238
242
naxes = len (columns )
239
243
fig , axes = create_subplots (
240
- naxes = naxes , sharex = True , sharey = True , figsize = figsize , ax = ax , layout = layout
244
+ naxes = naxes ,
245
+ sharex = kwargs .pop ("sharex" , True ),
246
+ sharey = kwargs .pop ("sharey" , True ),
247
+ figsize = figsize ,
248
+ ax = ax ,
249
+ layout = layout ,
241
250
)
242
251
243
252
_axes = flatten_axes (axes )
244
253
254
+ # GH 45465: move the "by" label based on "vert"
255
+ xlabel , ylabel = kwargs .pop ("xlabel" , None ), kwargs .pop ("ylabel" , None )
256
+ if kwargs .get ("vert" , True ):
257
+ xlabel = xlabel or by
258
+ else :
259
+ ylabel = ylabel or by
260
+
245
261
ax_values = []
246
262
247
263
for i , col in enumerate (columns ):
248
264
ax = _axes [i ]
249
265
gp_col = grouped [col ]
250
266
keys , values = zip (* gp_col )
251
- re_plotf = plotf (keys , values , ax , ** kwargs )
267
+ re_plotf = plotf (keys , values , ax , xlabel = xlabel , ylabel = ylabel , ** kwargs )
252
268
ax .set_title (col )
253
- ax .set_xlabel (pprint_thing (by ))
254
269
ax_values .append (re_plotf )
255
270
ax .grid (grid )
256
271
@@ -332,18 +347,28 @@ def maybe_color_bp(bp, **kwds):
332
347
if not kwds .get ("capprops" ):
333
348
setp (bp ["caps" ], color = colors [3 ], alpha = 1 )
334
349
335
- def plot_group (keys , values , ax : Axes ):
350
+ def plot_group (keys , values , ax : Axes , ** kwds ):
351
+ # GH 45465: xlabel/ylabel need to be popped out before plotting happens
352
+ xlabel , ylabel = kwds .pop ("xlabel" , None ), kwds .pop ("ylabel" , None )
353
+ if xlabel :
354
+ ax .set_xlabel (pprint_thing (xlabel ))
355
+ if ylabel :
356
+ ax .set_ylabel (pprint_thing (ylabel ))
357
+
336
358
keys = [pprint_thing (x ) for x in keys ]
337
359
values = [np .asarray (remove_na_arraylike (v ), dtype = object ) for v in values ]
338
360
bp = ax .boxplot (values , ** kwds )
339
361
if fontsize is not None :
340
362
ax .tick_params (axis = "both" , labelsize = fontsize )
341
- if kwds .get ("vert" , 1 ):
342
- ticks = ax .get_xticks ()
343
- if len (ticks ) != len (keys ):
344
- i , remainder = divmod (len (ticks ), len (keys ))
345
- assert remainder == 0 , remainder
346
- keys *= i
363
+
364
+ # GH 45465: x/y are flipped when "vert" changes
365
+ is_vertical = kwds .get ("vert" , True )
366
+ ticks = ax .get_xticks () if is_vertical else ax .get_yticks ()
367
+ if len (ticks ) != len (keys ):
368
+ i , remainder = divmod (len (ticks ), len (keys ))
369
+ assert remainder == 0 , remainder
370
+ keys *= i
371
+ if is_vertical :
347
372
ax .set_xticklabels (keys , rotation = rot )
348
373
else :
349
374
ax .set_yticklabels (keys , rotation = rot )
@@ -379,6 +404,7 @@ def plot_group(keys, values, ax: Axes):
379
404
ax = ax ,
380
405
layout = layout ,
381
406
return_type = return_type ,
407
+ ** kwds ,
382
408
)
383
409
else :
384
410
if return_type is None :
@@ -401,7 +427,7 @@ def plot_group(keys, values, ax: Axes):
401
427
else :
402
428
data = data [columns ]
403
429
404
- result = plot_group (columns , data .values .T , ax )
430
+ result = plot_group (columns , data .values .T , ax , ** kwds )
405
431
ax .grid (grid )
406
432
407
433
return result
0 commit comments