@@ -200,7 +200,11 @@ def _make_legend(self):
200200 pass
201201
202202 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 ))
204208
205209 @property
206210 def orientation (self ):
@@ -237,20 +241,31 @@ def _grouped_plot_by_column(
237241 columns = data ._get_numeric_data ().columns .difference (by )
238242 naxes = len (columns )
239243 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 ,
241250 )
242251
243252 _axes = flatten_axes (axes )
244253
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+
245261 ax_values = []
246262
247263 for i , col in enumerate (columns ):
248264 ax = _axes [i ]
249265 gp_col = grouped [col ]
250266 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 )
252268 ax .set_title (col )
253- ax .set_xlabel (pprint_thing (by ))
254269 ax_values .append (re_plotf )
255270 ax .grid (grid )
256271
@@ -332,18 +347,28 @@ def maybe_color_bp(bp, **kwds):
332347 if not kwds .get ("capprops" ):
333348 setp (bp ["caps" ], color = colors [3 ], alpha = 1 )
334349
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+
336358 keys = [pprint_thing (x ) for x in keys ]
337359 values = [np .asarray (remove_na_arraylike (v ), dtype = object ) for v in values ]
338360 bp = ax .boxplot (values , ** kwds )
339361 if fontsize is not None :
340362 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 :
347372 ax .set_xticklabels (keys , rotation = rot )
348373 else :
349374 ax .set_yticklabels (keys , rotation = rot )
@@ -379,6 +404,7 @@ def plot_group(keys, values, ax: Axes):
379404 ax = ax ,
380405 layout = layout ,
381406 return_type = return_type ,
407+ ** kwds ,
382408 )
383409 else :
384410 if return_type is None :
@@ -401,7 +427,7 @@ def plot_group(keys, values, ax: Axes):
401427 else :
402428 data = data [columns ]
403429
404- result = plot_group (columns , data .values .T , ax )
430+ result = plot_group (columns , data .values .T , ax , ** kwds )
405431 ax .grid (grid )
406432
407433 return result
0 commit comments