10
10
from matplotlib .artist import setp
11
11
import numpy as np
12
12
13
+ from pandas ._libs import lib
13
14
from pandas .util ._decorators import cache_readonly
14
15
from pandas .util ._exceptions import find_stack_level
15
16
@@ -113,26 +114,26 @@ def _plot( # type: ignore[override]
113
114
else :
114
115
return ax , bp
115
116
116
- def _validate_color_args (self ):
117
- if "color" in self .kwds :
118
- if self .colormap is not None :
119
- warnings .warn (
120
- "'color' and 'colormap' cannot be used "
121
- "simultaneously. Using 'color'" ,
122
- stacklevel = find_stack_level (),
123
- )
124
- self .color = self .kwds .pop ("color" )
117
+ def _validate_color_args (self , color , colormap ):
118
+ if color is lib .no_default :
119
+ return None
125
120
126
- if isinstance (self .color , dict ):
127
- valid_keys = ["boxes" , "whiskers" , "medians" , "caps" ]
128
- for key in self .color :
129
- if key not in valid_keys :
130
- raise ValueError (
131
- f"color dict contains invalid key '{ key } '. "
132
- f"The key must be either { valid_keys } "
133
- )
134
- else :
135
- self .color = None
121
+ if colormap is not None :
122
+ warnings .warn (
123
+ "'color' and 'colormap' cannot be used "
124
+ "simultaneously. Using 'color'" ,
125
+ stacklevel = find_stack_level (),
126
+ )
127
+
128
+ if isinstance (color , dict ):
129
+ valid_keys = ["boxes" , "whiskers" , "medians" , "caps" ]
130
+ for key in color :
131
+ if key not in valid_keys :
132
+ raise ValueError (
133
+ f"color dict contains invalid key '{ key } '. "
134
+ f"The key must be either { valid_keys } "
135
+ )
136
+ return color
136
137
137
138
@cache_readonly
138
139
def _color_attrs (self ):
@@ -182,16 +183,8 @@ def maybe_color_bp(self, bp) -> None:
182
183
medians = self .color or self ._medians_c
183
184
caps = self .color or self ._caps_c
184
185
185
- # GH 30346, when users specifying those arguments explicitly, our defaults
186
- # for these four kwargs should be overridden; if not, use Pandas settings
187
- if not self .kwds .get ("boxprops" ):
188
- setp (bp ["boxes" ], color = boxes , alpha = 1 )
189
- if not self .kwds .get ("whiskerprops" ):
190
- setp (bp ["whiskers" ], color = whiskers , alpha = 1 )
191
- if not self .kwds .get ("medianprops" ):
192
- setp (bp ["medians" ], color = medians , alpha = 1 )
193
- if not self .kwds .get ("capprops" ):
194
- setp (bp ["caps" ], color = caps , alpha = 1 )
186
+ color_tup = (boxes , whiskers , medians , caps )
187
+ maybe_color_bp (bp , color_tup = color_tup , ** self .kwds )
195
188
196
189
def _make_plot (self , fig : Figure ) -> None :
197
190
if self .subplots :
@@ -276,6 +269,19 @@ def result(self):
276
269
return self ._return_obj
277
270
278
271
272
+ def maybe_color_bp (bp , color_tup , ** kwds ) -> None :
273
+ # GH#30346, when users specifying those arguments explicitly, our defaults
274
+ # for these four kwargs should be overridden; if not, use Pandas settings
275
+ if not kwds .get ("boxprops" ):
276
+ setp (bp ["boxes" ], color = color_tup [0 ], alpha = 1 )
277
+ if not kwds .get ("whiskerprops" ):
278
+ setp (bp ["whiskers" ], color = color_tup [1 ], alpha = 1 )
279
+ if not kwds .get ("medianprops" ):
280
+ setp (bp ["medians" ], color = color_tup [2 ], alpha = 1 )
281
+ if not kwds .get ("capprops" ):
282
+ setp (bp ["caps" ], color = color_tup [3 ], alpha = 1 )
283
+
284
+
279
285
def _grouped_plot_by_column (
280
286
plotf ,
281
287
data ,
@@ -389,18 +395,6 @@ def _get_colors():
389
395
390
396
return result
391
397
392
- def maybe_color_bp (bp , ** kwds ) -> None :
393
- # GH 30346, when users specifying those arguments explicitly, our defaults
394
- # for these four kwargs should be overridden; if not, use Pandas settings
395
- if not kwds .get ("boxprops" ):
396
- setp (bp ["boxes" ], color = colors [0 ], alpha = 1 )
397
- if not kwds .get ("whiskerprops" ):
398
- setp (bp ["whiskers" ], color = colors [1 ], alpha = 1 )
399
- if not kwds .get ("medianprops" ):
400
- setp (bp ["medians" ], color = colors [2 ], alpha = 1 )
401
- if not kwds .get ("capprops" ):
402
- setp (bp ["caps" ], color = colors [3 ], alpha = 1 )
403
-
404
398
def plot_group (keys , values , ax : Axes , ** kwds ):
405
399
# GH 45465: xlabel/ylabel need to be popped out before plotting happens
406
400
xlabel , ylabel = kwds .pop ("xlabel" , None ), kwds .pop ("ylabel" , None )
@@ -419,7 +413,7 @@ def plot_group(keys, values, ax: Axes, **kwds):
419
413
_set_ticklabels (
420
414
ax = ax , labels = keys , is_vertical = kwds .get ("vert" , True ), rotation = rot
421
415
)
422
- maybe_color_bp (bp , ** kwds )
416
+ maybe_color_bp (bp , color_tup = colors , ** kwds )
423
417
424
418
# Return axes in multiplot case, maybe revisit later # 985
425
419
if return_type == "dict" :
0 commit comments