39
39
import matplotlib .transforms as mtrans
40
40
from matplotlib .container import BarContainer , ErrorbarContainer , StemContainer
41
41
from matplotlib .axes ._base import _AxesBase
42
+ from matplotlib .axes ._base import _process_plot_format
42
43
43
44
iterable = cbook .iterable
44
45
is_string_like = cbook .is_string_like
@@ -2887,18 +2888,19 @@ def boxplot(self, x, notch=False, sym='b+', vert=True, whis=1.5,
2887
2888
meanline = False , showmeans = False , showcaps = True ,
2888
2889
showbox = True , showfliers = True , boxprops = None , labels = None ,
2889
2890
flierprops = None , medianprops = None , meanprops = None ,
2890
- manage_xticks = True ):
2891
+ capprops = None , whiskerprops = None , manage_xticks = True ):
2891
2892
"""
2892
2893
Make a box and whisker plot.
2893
2894
2894
2895
Call signature::
2895
2896
2896
- boxplot(x, notch=False, sym='b+', vert=True, whis=1.5,
2897
+ boxplot(self, x, notch=False, sym='b+', vert=True, whis=1.5,
2897
2898
positions=None, widths=None, patch_artist=False,
2898
2899
bootstrap=None, usermedians=None, conf_intervals=None,
2899
2900
meanline=False, showmeans=False, showcaps=True,
2900
2901
showbox=True, showfliers=True, boxprops=None, labels=None,
2901
- flierprops=None, medianprops=None, meanprops=None)
2902
+ flierprops=None, medianprops=None, meanprops=None,
2903
+ capprops=None, whiskerprops=None, manage_xticks=True):
2902
2904
2903
2905
Make a box and whisker plot for each column of *x* or each
2904
2906
vector in sequence *x*. The box extends from the lower to
@@ -2994,6 +2996,12 @@ def boxplot(self, x, notch=False, sym='b+', vert=True, whis=1.5,
2994
2996
boxprops : dict or None (default)
2995
2997
If provided, will set the plotting style of the boxes
2996
2998
2999
+ whiskerprops : dict or None (default)
3000
+ If provided, will set the plotting style of the whiskers
3001
+
3002
+ capprops : dict or None (default)
3003
+ If provided, will set the plotting style of the caps
3004
+
2997
3005
flierprops : dict or None (default)
2998
3006
If provided, will set the plotting style of the fliers
2999
3007
@@ -3034,14 +3042,15 @@ def boxplot(self, x, notch=False, sym='b+', vert=True, whis=1.5,
3034
3042
"""
3035
3043
bxpstats = cbook .boxplot_stats (x , whis = whis , bootstrap = bootstrap ,
3036
3044
labels = labels )
3037
- if sym == 'b+' and flierprops is None :
3038
- flierprops = dict (linestyle = 'none' , marker = '+' ,
3039
- markeredgecolor = 'blue' )
3045
+ if flierprops is None :
3046
+ flierprops = dict (sym = sym )
3047
+ else :
3048
+ flierprops ['sym' ] = sym
3040
3049
3041
3050
# replace medians if necessary:
3042
3051
if usermedians is not None :
3043
3052
if (len (np .ravel (usermedians )) != len (bxpstats ) or
3044
- np .shape (usermedians )[0 ] != len (bxpstats )):
3053
+ np .shape (usermedians )[0 ] != len (bxpstats )):
3045
3054
medmsg = 'usermedians length not compatible with x'
3046
3055
raise ValueError (medmsg )
3047
3056
else :
@@ -3073,24 +3082,27 @@ def boxplot(self, x, notch=False, sym='b+', vert=True, whis=1.5,
3073
3082
boxprops = boxprops , flierprops = flierprops ,
3074
3083
medianprops = medianprops , meanprops = meanprops ,
3075
3084
meanline = meanline , showfliers = showfliers ,
3085
+ capprops = capprops , whiskerprops = whiskerprops ,
3076
3086
manage_xticks = manage_xticks )
3077
3087
return artists
3078
3088
3079
3089
def bxp (self , bxpstats , positions = None , widths = None , vert = True ,
3080
3090
patch_artist = False , shownotches = False , showmeans = False ,
3081
3091
showcaps = True , showbox = True , showfliers = True ,
3082
- boxprops = None , flierprops = None , medianprops = None ,
3083
- meanprops = None , meanline = False , manage_xticks = True ):
3092
+ boxprops = None , whiskerprops = None , flierprops = None ,
3093
+ medianprops = None , capprops = None , meanprops = None ,
3094
+ meanline = False , manage_xticks = True ):
3084
3095
"""
3085
3096
Drawing function for box and whisker plots.
3086
3097
3087
3098
Call signature::
3088
3099
3089
- bxp(bxpstats, positions=None, widths=None, vert=True,
3100
+ bxp(self, bxpstats, positions=None, widths=None, vert=True,
3090
3101
patch_artist=False, shownotches=False, showmeans=False,
3091
3102
showcaps=True, showbox=True, showfliers=True,
3092
- boxprops=None, flierprops=None, medianprops=None,
3093
- meanprops=None, meanline=False, manage_xticks=True)
3103
+ boxprops=None, whiskerprops=None, flierprops=None,
3104
+ medianprops=None, capprops=None, meanprops=None,
3105
+ meanline=False, manage_xticks=True):
3094
3106
3095
3107
Make a box and whisker plot for each column of *x* or each
3096
3108
vector in sequence *x*. The box extends from the lower to
@@ -3136,14 +3148,14 @@ def bxp(self, bxpstats, positions=None, widths=None, vert=True,
3136
3148
If True produces boxes with the Patch artist
3137
3149
3138
3150
shownotches : bool, default = False
3139
- If False (default), produces a rectangular box plot.
3140
- If True, will produce a notched box plot
3151
+ If False (default), produces a rectangular box plot.
3152
+ If True, will produce a notched box plot
3141
3153
3142
3154
showmeans : bool, default = False
3143
3155
If True, will toggle one the rendering of the means
3144
3156
3145
3157
showcaps : bool, default = True
3146
- If True, will toggle one the rendering of the caps
3158
+ If True will toggle one the rendering of the caps
3147
3159
3148
3160
showbox : bool, default = True
3149
3161
If True, will toggle one the rendering of box
@@ -3154,8 +3166,14 @@ def bxp(self, bxpstats, positions=None, widths=None, vert=True,
3154
3166
boxprops : dict or None (default)
3155
3167
If provided, will set the plotting style of the boxes
3156
3168
3169
+ whiskerprops : dict or None (default)
3170
+ If provided, will set the plotting style of the whiskers
3171
+
3172
+ capprops : dict or None (default)
3173
+ If provided, will set the plotting style of the caps
3174
+
3157
3175
flierprops : dict or None (default)
3158
- If provided, will set the plotting style of the fliers
3176
+ If provided will set the plotting style of the fliers
3159
3177
3160
3178
medianprops : dict or None (default)
3161
3179
If provided, will set the plotting style of the medians
@@ -3219,37 +3237,58 @@ def bxp(self, bxpstats, positions=None, widths=None, vert=True,
3219
3237
final_boxprops = dict (linestyle = 'solid' , edgecolor = 'black' ,
3220
3238
facecolor = 'white' , linewidth = 1 )
3221
3239
else :
3222
- final_boxprops = dict (linestyle = '-' , color = 'black' , linewidth = 1 )
3240
+ final_boxprops = dict (linestyle = '-' , color = 'blue' )
3223
3241
3224
3242
if boxprops is not None :
3225
3243
final_boxprops .update (boxprops )
3226
3244
3227
3245
# other (cap, whisker) properties
3228
- if patch_artist :
3229
- otherprops = dict (
3230
- linestyle = linestyle_map [final_boxprops ['linestyle' ]],
3231
- color = final_boxprops ['edgecolor' ],
3232
- linewidth = final_boxprops .get ('linewidth' , 1 )
3233
- )
3234
- else :
3235
- otherprops = dict (linestyle = final_boxprops ['linestyle' ],
3236
- color = final_boxprops ['color' ],
3237
- linewidth = final_boxprops .get ('linewidth' , 1 ))
3246
+ final_whiskerprops = dict (
3247
+ linestyle = '--' ,
3248
+ color = 'blue' ,
3249
+ )
3238
3250
3239
- # flier (outlier) properties
3251
+ final_capprops = dict (
3252
+ linestyle = '-' ,
3253
+ color = 'black' ,
3254
+ )
3255
+
3256
+ if capprops is not None :
3257
+ final_capprops .update (capprops )
3258
+
3259
+ if whiskerprops is not None :
3260
+ final_whiskerprops .update (whiskerprops )
3261
+
3262
+ # set up the default flier properties
3240
3263
final_flierprops = dict (linestyle = 'none' , marker = '+' ,
3241
- markeredgecolor = 'blue' )
3264
+ markeredgecolor = 'b' ,
3265
+ markerfacecolor = 'none' )
3266
+ # flier (outlier) properties
3242
3267
if flierprops is not None :
3268
+ sym = flierprops .pop ('sym' , None )
3269
+
3270
+ # watch inverted logic, checks for non-default
3271
+ # value of `sym`
3272
+ if not (sym == '' or (sym is None )):
3273
+ # process the symbol string
3274
+ # discarded linestyle
3275
+ _ , marker , color = _process_plot_format (sym )
3276
+ flierprops ['marker' ] = marker
3277
+ flierprops ['color' ] = color
3278
+ # assume that if color is passed in the user want
3279
+ # filled symbol
3280
+ flierprops ['markeredgecolor' ] = color
3281
+ flierprops ['markerfacecolor' ] = color
3243
3282
final_flierprops .update (flierprops )
3244
3283
3245
3284
# median line properties
3246
- final_medianprops = dict (linestyle = '-' , color = 'blue ' )
3285
+ final_medianprops = dict (linestyle = '-' , color = 'red ' )
3247
3286
if medianprops is not None :
3248
3287
final_medianprops .update (medianprops )
3249
3288
3250
3289
# mean (line or point) properties
3251
3290
if meanline :
3252
- final_meanprops = dict (linestyle = '--' , color = 'red ' )
3291
+ final_meanprops = dict (linestyle = '--' , color = 'black ' )
3253
3292
else :
3254
3293
final_meanprops = dict (linestyle = 'none' , markerfacecolor = 'red' ,
3255
3294
marker = 's' )
@@ -3317,11 +3356,9 @@ def dopatch(xs, ys, **kwargs):
3317
3356
if not self ._hold :
3318
3357
self .cla ()
3319
3358
holdStatus = self ._hold
3320
-
3321
3359
for pos , width , stats in zip (positions , widths , bxpstats ):
3322
3360
# try to find a new label
3323
3361
datalabels .append (stats .get ('label' , pos ))
3324
-
3325
3362
# fliers coords
3326
3363
flier_x = np .ones (len (stats ['fliers' ])) * pos
3327
3364
flier_y = stats ['fliers' ]
@@ -3369,13 +3406,17 @@ def dopatch(xs, ys, **kwargs):
3369
3406
boxes .extend (doplot (box_x , box_y , ** final_boxprops ))
3370
3407
3371
3408
# draw the whiskers
3372
- whiskers .extend (doplot (whisker_x , whiskerlo_y , ** otherprops ))
3373
- whiskers .extend (doplot (whisker_x , whiskerhi_y , ** otherprops ))
3409
+ whiskers .extend (doplot (
3410
+ whisker_x , whiskerlo_y , ** final_whiskerprops
3411
+ ))
3412
+ whiskers .extend (doplot (
3413
+ whisker_x , whiskerhi_y , ** final_whiskerprops
3414
+ ))
3374
3415
3375
3416
# maybe draw the caps:
3376
3417
if showcaps :
3377
- caps .extend (doplot (cap_x , cap_lo , ** otherprops ))
3378
- caps .extend (doplot (cap_x , cap_hi , ** otherprops ))
3418
+ caps .extend (doplot (cap_x , cap_lo , ** final_capprops ))
3419
+ caps .extend (doplot (cap_x , cap_hi , ** final_capprops ))
3379
3420
3380
3421
# draw the medians
3381
3422
medians .extend (doplot (med_x , med_y , ** final_medianprops ))
@@ -3394,7 +3435,9 @@ def dopatch(xs, ys, **kwargs):
3394
3435
3395
3436
# maybe draw the fliers
3396
3437
if showfliers :
3397
- fliers .extend (doplot (flier_x , flier_y , ** final_flierprops ))
3438
+ fliers .extend (doplot (
3439
+ flier_x , flier_y , ** final_flierprops
3440
+ ))
3398
3441
3399
3442
# fix our axes/ticks up a little
3400
3443
if vert :
0 commit comments