@@ -3746,7 +3746,7 @@ def boxplot(self, x, notch=None, sym=None, vert=None, whis=None,
3746
3746
3747
3747
# if non-default sym value, put it into the flier dictionary
3748
3748
# the logic for providing the default symbol ('b+') now lives
3749
- # in bxp in the initial value of final_flierprops
3749
+ # in bxp in the initial value of flierkw
3750
3750
# handle all of the *sym* related logic here so we only have to pass
3751
3751
# on the flierprops dict.
3752
3752
if sym is not None :
@@ -3974,72 +3974,47 @@ def bxp(self, bxpstats, positions=None, widths=None, vert=True,
3974
3974
3975
3975
zdelta = 0.1
3976
3976
3977
- def line_props_with_rcdefaults (subkey , explicit , zdelta = 0 ,
3978
- use_marker = True ):
3977
+ def merge_kw_rc (subkey , explicit , zdelta = 0 , usemarker = True ):
3979
3978
d = {k .split ('.' )[- 1 ]: v for k , v in rcParams .items ()
3980
- if k .startswith (f'boxplot.{ subkey } ' )}
3979
+ if k .startswith (f'boxplot.{ subkey } props ' )}
3981
3980
d ['zorder' ] = zorder + zdelta
3982
- if not use_marker :
3981
+ if not usemarker :
3983
3982
d ['marker' ] = ''
3984
3983
d .update (cbook .normalize_kwargs (explicit , mlines .Line2D ))
3985
3984
return d
3986
3985
3987
- # box properties
3988
- if patch_artist :
3989
- final_boxprops = {
3990
- 'linestyle' : rcParams ['boxplot.boxprops.linestyle' ],
3991
- 'linewidth' : rcParams ['boxplot.boxprops.linewidth' ],
3992
- 'edgecolor' : rcParams ['boxplot.boxprops.color' ],
3993
- 'facecolor' : ('white' if rcParams ['_internal.classic_mode' ]
3994
- else rcParams ['patch.facecolor' ]),
3995
- 'zorder' : zorder ,
3996
- ** cbook .normalize_kwargs (boxprops , mpatches .PathPatch )
3997
- }
3998
- else :
3999
- final_boxprops = line_props_with_rcdefaults ('boxprops' , boxprops ,
4000
- use_marker = False )
4001
- final_whiskerprops = line_props_with_rcdefaults (
4002
- 'whiskerprops' , whiskerprops , use_marker = False )
4003
- final_capprops = line_props_with_rcdefaults (
4004
- 'capprops' , capprops , use_marker = False )
4005
- final_flierprops = line_props_with_rcdefaults (
4006
- 'flierprops' , flierprops )
4007
- final_medianprops = line_props_with_rcdefaults (
4008
- 'medianprops' , medianprops , zdelta , use_marker = False )
4009
- final_meanprops = line_props_with_rcdefaults (
4010
- 'meanprops' , meanprops , zdelta )
3986
+ box_kw = {
3987
+ 'linestyle' : rcParams ['boxplot.boxprops.linestyle' ],
3988
+ 'linewidth' : rcParams ['boxplot.boxprops.linewidth' ],
3989
+ 'edgecolor' : rcParams ['boxplot.boxprops.color' ],
3990
+ 'facecolor' : ('white' if rcParams ['_internal.classic_mode' ]
3991
+ else rcParams ['patch.facecolor' ]),
3992
+ 'zorder' : zorder ,
3993
+ ** cbook .normalize_kwargs (boxprops , mpatches .PathPatch )
3994
+ } if patch_artist else merge_kw_rc ('box' , boxprops , usemarker = False )
3995
+ whisker_kw = merge_kw_rc ('whisker' , whiskerprops , usemarker = False )
3996
+ cap_kw = merge_kw_rc ('cap' , capprops , usemarker = False )
3997
+ flier_kw = merge_kw_rc ('flier' , flierprops )
3998
+ median_kw = merge_kw_rc ('median' , medianprops , zdelta , usemarker = False )
3999
+ mean_kw = merge_kw_rc ('mean' , meanprops , zdelta )
4011
4000
removed_prop = 'marker' if meanline else 'linestyle'
4012
4001
# Only remove the property if it's not set explicitly as a parameter.
4013
4002
if meanprops is None or removed_prop not in meanprops :
4014
- final_meanprops [removed_prop ] = ''
4015
-
4016
- def patch_list (xs , ys , ** kwargs ):
4017
- path = mpath .Path (
4018
- # Last vertex will have a CLOSEPOLY code and thus be ignored.
4019
- np .append (np .column_stack ([xs , ys ]), [(0 , 0 )], 0 ),
4020
- closed = True )
4021
- patch = mpatches .PathPatch (path , ** kwargs )
4022
- self .add_artist (patch )
4023
- return [patch ]
4003
+ mean_kw [removed_prop ] = ''
4024
4004
4025
4005
# vertical or horizontal plot?
4026
- if vert :
4027
- def doplot (* args , ** kwargs ):
4028
- return self .plot (* args , ** kwargs )
4029
-
4030
- def dopatch (xs , ys , ** kwargs ):
4031
- return patch_list (xs , ys , ** kwargs )
4006
+ maybe_swap = slice (None ) if vert else slice (None , None , - 1 )
4032
4007
4033
- else :
4034
- def doplot (* args , ** kwargs ):
4035
- shuffled = []
4036
- for i in range (0 , len (args ), 2 ):
4037
- shuffled .extend ([args [i + 1 ], args [i ]])
4038
- return self .plot (* shuffled , ** kwargs )
4008
+ def do_plot (xs , ys , ** kwargs ):
4009
+ return self .plot (* [xs , ys ][maybe_swap ], ** kwargs )[0 ]
4039
4010
4040
- def dopatch (xs , ys , ** kwargs ):
4041
- xs , ys = ys , xs # flip X, Y
4042
- return patch_list (xs , ys , ** kwargs )
4011
+ def do_patch (xs , ys , ** kwargs ):
4012
+ path = mpath .Path (
4013
+ # Last (0, 0) vertex has a CLOSEPOLY code and is thus ignored.
4014
+ np .column_stack ([[* xs , 0 ], [* ys , 0 ]][maybe_swap ]), closed = True )
4015
+ patch = mpatches .PathPatch (path , ** kwargs )
4016
+ self .add_artist (patch )
4017
+ return patch
4043
4018
4044
4019
# input validation
4045
4020
N = len (bxpstats )
@@ -4068,22 +4043,19 @@ def dopatch(xs, ys, **kwargs):
4068
4043
datalabels .append (stats .get ('label' , pos ))
4069
4044
4070
4045
# whisker coords
4071
- whisker_x = np .ones (2 ) * pos
4072
- whiskerlo_y = np .array ([stats ['q1' ], stats ['whislo' ]])
4073
- whiskerhi_y = np .array ([stats ['q3' ], stats ['whishi' ]])
4074
-
4046
+ whis_x = [pos , pos ]
4047
+ whislo_y = [stats ['q1' ], stats ['whislo' ]]
4048
+ whishi_y = [stats ['q3' ], stats ['whishi' ]]
4075
4049
# cap coords
4076
4050
cap_left = pos - width * 0.25
4077
4051
cap_right = pos + width * 0.25
4078
- cap_x = np .array ([cap_left , cap_right ])
4079
- cap_lo = np .ones (2 ) * stats ['whislo' ]
4080
- cap_hi = np .ones (2 ) * stats ['whishi' ]
4081
-
4052
+ cap_x = [cap_left , cap_right ]
4053
+ cap_lo = np .full (2 , stats ['whislo' ])
4054
+ cap_hi = np .full (2 , stats ['whishi' ])
4082
4055
# box and median coords
4083
4056
box_left = pos - width * 0.5
4084
4057
box_right = pos + width * 0.5
4085
4058
med_y = [stats ['med' ], stats ['med' ]]
4086
-
4087
4059
# notched boxes
4088
4060
if shownotches :
4089
4061
box_x = [box_left , box_right , box_right , cap_right , box_right ,
@@ -4094,58 +4066,40 @@ def dopatch(xs, ys, **kwargs):
4094
4066
stats ['q3' ], stats ['cihi' ], stats ['med' ],
4095
4067
stats ['cilo' ], stats ['q1' ]]
4096
4068
med_x = cap_x
4097
-
4098
4069
# plain boxes
4099
4070
else :
4100
4071
box_x = [box_left , box_right , box_right , box_left , box_left ]
4101
4072
box_y = [stats ['q1' ], stats ['q1' ], stats ['q3' ], stats ['q3' ],
4102
4073
stats ['q1' ]]
4103
4074
med_x = [box_left , box_right ]
4104
4075
4105
- # maybe draw the box:
4076
+ # maybe draw the box
4106
4077
if showbox :
4107
- if patch_artist :
4108
- boxes .extend (dopatch (box_x , box_y , ** final_boxprops ))
4109
- else :
4110
- boxes .extend (doplot (box_x , box_y , ** final_boxprops ))
4111
-
4078
+ do_box = do_patch if patch_artist else do_plot
4079
+ boxes .append (do_box (box_x , box_y , ** box_kw ))
4112
4080
# draw the whiskers
4113
- whiskers .extend (doplot (
4114
- whisker_x , whiskerlo_y , ** final_whiskerprops
4115
- ))
4116
- whiskers .extend (doplot (
4117
- whisker_x , whiskerhi_y , ** final_whiskerprops
4118
- ))
4119
-
4120
- # maybe draw the caps:
4081
+ whiskers .append (do_plot (whis_x , whislo_y , ** whisker_kw ))
4082
+ whiskers .append (do_plot (whis_x , whishi_y , ** whisker_kw ))
4083
+ # maybe draw the caps
4121
4084
if showcaps :
4122
- caps .extend (doplot (cap_x , cap_lo , ** final_capprops ))
4123
- caps .extend (doplot (cap_x , cap_hi , ** final_capprops ))
4124
-
4085
+ caps .append (do_plot (cap_x , cap_lo , ** cap_kw ))
4086
+ caps .append (do_plot (cap_x , cap_hi , ** cap_kw ))
4125
4087
# draw the medians
4126
- medians .extend (doplot (med_x , med_y , ** final_medianprops ))
4127
-
4088
+ medians .append (do_plot (med_x , med_y , ** median_kw ))
4128
4089
# maybe draw the means
4129
4090
if showmeans :
4130
4091
if meanline :
4131
- means .extend ( doplot (
4092
+ means .append ( do_plot (
4132
4093
[box_left , box_right ], [stats ['mean' ], stats ['mean' ]],
4133
- ** final_meanprops
4094
+ ** mean_kw
4134
4095
))
4135
4096
else :
4136
- means .extend (doplot (
4137
- [pos ], [stats ['mean' ]], ** final_meanprops
4138
- ))
4139
-
4097
+ means .append (do_plot ([pos ], [stats ['mean' ]], ** mean_kw ))
4140
4098
# maybe draw the fliers
4141
4099
if showfliers :
4142
- # fliers coords
4143
4100
flier_x = np .full (len (stats ['fliers' ]), pos , dtype = np .float64 )
4144
4101
flier_y = stats ['fliers' ]
4145
-
4146
- fliers .extend (doplot (
4147
- flier_x , flier_y , ** final_flierprops
4148
- ))
4102
+ fliers .append (do_plot (flier_x , flier_y , ** flier_kw ))
4149
4103
4150
4104
if manage_ticks :
4151
4105
axis_name = "x" if vert else "y"
0 commit comments