@@ -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 :
@@ -3925,72 +3925,47 @@ def bxp(self, bxpstats, positions=None, widths=None, vert=True,
3925
3925
3926
3926
zdelta = 0.1
3927
3927
3928
- def line_props_with_rcdefaults (subkey , explicit , zdelta = 0 ,
3929
- use_marker = True ):
3928
+ def merge_kw_rc (subkey , explicit , zdelta = 0 , usemarker = True ):
3930
3929
d = {k .split ('.' )[- 1 ]: v for k , v in rcParams .items ()
3931
- if k .startswith (f'boxplot.{ subkey } ' )}
3930
+ if k .startswith (f'boxplot.{ subkey } props ' )}
3932
3931
d ['zorder' ] = zorder + zdelta
3933
- if not use_marker :
3932
+ if not usemarker :
3934
3933
d ['marker' ] = ''
3935
3934
d .update (cbook .normalize_kwargs (explicit , mlines .Line2D ))
3936
3935
return d
3937
3936
3938
- # box properties
3939
- if patch_artist :
3940
- final_boxprops = {
3941
- 'linestyle' : rcParams ['boxplot.boxprops.linestyle' ],
3942
- 'linewidth' : rcParams ['boxplot.boxprops.linewidth' ],
3943
- 'edgecolor' : rcParams ['boxplot.boxprops.color' ],
3944
- 'facecolor' : ('white' if rcParams ['_internal.classic_mode' ]
3945
- else rcParams ['patch.facecolor' ]),
3946
- 'zorder' : zorder ,
3947
- ** cbook .normalize_kwargs (boxprops , mpatches .PathPatch )
3948
- }
3949
- else :
3950
- final_boxprops = line_props_with_rcdefaults ('boxprops' , boxprops ,
3951
- use_marker = False )
3952
- final_whiskerprops = line_props_with_rcdefaults (
3953
- 'whiskerprops' , whiskerprops , use_marker = False )
3954
- final_capprops = line_props_with_rcdefaults (
3955
- 'capprops' , capprops , use_marker = False )
3956
- final_flierprops = line_props_with_rcdefaults (
3957
- 'flierprops' , flierprops )
3958
- final_medianprops = line_props_with_rcdefaults (
3959
- 'medianprops' , medianprops , zdelta , use_marker = False )
3960
- final_meanprops = line_props_with_rcdefaults (
3961
- 'meanprops' , meanprops , zdelta )
3937
+ box_kw = {
3938
+ 'linestyle' : rcParams ['boxplot.boxprops.linestyle' ],
3939
+ 'linewidth' : rcParams ['boxplot.boxprops.linewidth' ],
3940
+ 'edgecolor' : rcParams ['boxplot.boxprops.color' ],
3941
+ 'facecolor' : ('white' if rcParams ['_internal.classic_mode' ]
3942
+ else rcParams ['patch.facecolor' ]),
3943
+ 'zorder' : zorder ,
3944
+ ** cbook .normalize_kwargs (boxprops , mpatches .PathPatch )
3945
+ } if patch_artist else merge_kw_rc ('box' , boxprops , usemarker = False )
3946
+ whisker_kw = merge_kw_rc ('whisker' , whiskerprops , usemarker = False )
3947
+ cap_kw = merge_kw_rc ('cap' , capprops , usemarker = False )
3948
+ flier_kw = merge_kw_rc ('flier' , flierprops )
3949
+ median_kw = merge_kw_rc ('median' , medianprops , zdelta , usemarker = False )
3950
+ mean_kw = merge_kw_rc ('mean' , meanprops , zdelta )
3962
3951
removed_prop = 'marker' if meanline else 'linestyle'
3963
3952
# Only remove the property if it's not set explicitly as a parameter.
3964
3953
if meanprops is None or removed_prop not in meanprops :
3965
- final_meanprops [removed_prop ] = ''
3966
-
3967
- def patch_list (xs , ys , ** kwargs ):
3968
- path = mpath .Path (
3969
- # Last vertex will have a CLOSEPOLY code and thus be ignored.
3970
- np .append (np .column_stack ([xs , ys ]), [(0 , 0 )], 0 ),
3971
- closed = True )
3972
- patch = mpatches .PathPatch (path , ** kwargs )
3973
- self .add_artist (patch )
3974
- return [patch ]
3954
+ mean_kw [removed_prop ] = ''
3975
3955
3976
3956
# vertical or horizontal plot?
3977
- if vert :
3978
- def doplot (* args , ** kwargs ):
3979
- return self .plot (* args , ** kwargs )
3980
-
3981
- def dopatch (xs , ys , ** kwargs ):
3982
- return patch_list (xs , ys , ** kwargs )
3957
+ maybe_swap = slice (None ) if vert else slice (None , None , - 1 )
3983
3958
3984
- else :
3985
- def doplot (* args , ** kwargs ):
3986
- shuffled = []
3987
- for i in range (0 , len (args ), 2 ):
3988
- shuffled .extend ([args [i + 1 ], args [i ]])
3989
- return self .plot (* shuffled , ** kwargs )
3959
+ def do_plot (xs , ys , ** kwargs ):
3960
+ return self .plot (* [xs , ys ][maybe_swap ], ** kwargs )[0 ]
3990
3961
3991
- def dopatch (xs , ys , ** kwargs ):
3992
- xs , ys = ys , xs # flip X, Y
3993
- return patch_list (xs , ys , ** kwargs )
3962
+ def do_patch (xs , ys , ** kwargs ):
3963
+ path = mpath .Path (
3964
+ # Last (0, 0) vertex has a CLOSEPOLY code and is thus ignored.
3965
+ np .column_stack ([[* xs , 0 ], [* ys , 0 ]][maybe_swap ]), closed = True )
3966
+ patch = mpatches .PathPatch (path , ** kwargs )
3967
+ self .add_artist (patch )
3968
+ return patch
3994
3969
3995
3970
# input validation
3996
3971
N = len (bxpstats )
@@ -4019,22 +3994,19 @@ def dopatch(xs, ys, **kwargs):
4019
3994
datalabels .append (stats .get ('label' , pos ))
4020
3995
4021
3996
# whisker coords
4022
- whisker_x = np .ones (2 ) * pos
4023
- whiskerlo_y = np .array ([stats ['q1' ], stats ['whislo' ]])
4024
- whiskerhi_y = np .array ([stats ['q3' ], stats ['whishi' ]])
4025
-
3997
+ whis_x = [pos , pos ]
3998
+ whislo_y = [stats ['q1' ], stats ['whislo' ]]
3999
+ whishi_y = [stats ['q3' ], stats ['whishi' ]]
4026
4000
# cap coords
4027
4001
cap_left = pos - width * 0.25
4028
4002
cap_right = pos + width * 0.25
4029
- cap_x = np .array ([cap_left , cap_right ])
4030
- cap_lo = np .ones (2 ) * stats ['whislo' ]
4031
- cap_hi = np .ones (2 ) * stats ['whishi' ]
4032
-
4003
+ cap_x = [cap_left , cap_right ]
4004
+ cap_lo = np .full (2 , stats ['whislo' ])
4005
+ cap_hi = np .full (2 , stats ['whishi' ])
4033
4006
# box and median coords
4034
4007
box_left = pos - width * 0.5
4035
4008
box_right = pos + width * 0.5
4036
4009
med_y = [stats ['med' ], stats ['med' ]]
4037
-
4038
4010
# notched boxes
4039
4011
if shownotches :
4040
4012
box_x = [box_left , box_right , box_right , cap_right , box_right ,
@@ -4045,58 +4017,40 @@ def dopatch(xs, ys, **kwargs):
4045
4017
stats ['q3' ], stats ['cihi' ], stats ['med' ],
4046
4018
stats ['cilo' ], stats ['q1' ]]
4047
4019
med_x = cap_x
4048
-
4049
4020
# plain boxes
4050
4021
else :
4051
4022
box_x = [box_left , box_right , box_right , box_left , box_left ]
4052
4023
box_y = [stats ['q1' ], stats ['q1' ], stats ['q3' ], stats ['q3' ],
4053
4024
stats ['q1' ]]
4054
4025
med_x = [box_left , box_right ]
4055
4026
4056
- # maybe draw the box:
4027
+ # maybe draw the box
4057
4028
if showbox :
4058
- if patch_artist :
4059
- boxes .extend (dopatch (box_x , box_y , ** final_boxprops ))
4060
- else :
4061
- boxes .extend (doplot (box_x , box_y , ** final_boxprops ))
4062
-
4029
+ do_box = do_patch if patch_artist else do_plot
4030
+ boxes .append (do_box (box_x , box_y , ** box_kw ))
4063
4031
# draw the whiskers
4064
- whiskers .extend (doplot (
4065
- whisker_x , whiskerlo_y , ** final_whiskerprops
4066
- ))
4067
- whiskers .extend (doplot (
4068
- whisker_x , whiskerhi_y , ** final_whiskerprops
4069
- ))
4070
-
4071
- # maybe draw the caps:
4032
+ whiskers .append (do_plot (whis_x , whislo_y , ** whisker_kw ))
4033
+ whiskers .append (do_plot (whis_x , whishi_y , ** whisker_kw ))
4034
+ # maybe draw the caps
4072
4035
if showcaps :
4073
- caps .extend (doplot (cap_x , cap_lo , ** final_capprops ))
4074
- caps .extend (doplot (cap_x , cap_hi , ** final_capprops ))
4075
-
4036
+ caps .append (do_plot (cap_x , cap_lo , ** cap_kw ))
4037
+ caps .append (do_plot (cap_x , cap_hi , ** cap_kw ))
4076
4038
# draw the medians
4077
- medians .extend (doplot (med_x , med_y , ** final_medianprops ))
4078
-
4039
+ medians .append (do_plot (med_x , med_y , ** median_kw ))
4079
4040
# maybe draw the means
4080
4041
if showmeans :
4081
4042
if meanline :
4082
- means .extend ( doplot (
4043
+ means .append ( do_plot (
4083
4044
[box_left , box_right ], [stats ['mean' ], stats ['mean' ]],
4084
- ** final_meanprops
4045
+ ** mean_kw
4085
4046
))
4086
4047
else :
4087
- means .extend (doplot (
4088
- [pos ], [stats ['mean' ]], ** final_meanprops
4089
- ))
4090
-
4048
+ means .append (do_plot ([pos ], [stats ['mean' ]], ** mean_kw ))
4091
4049
# maybe draw the fliers
4092
4050
if showfliers :
4093
- # fliers coords
4094
4051
flier_x = np .full (len (stats ['fliers' ]), pos , dtype = np .float64 )
4095
4052
flier_y = stats ['fliers' ]
4096
-
4097
- fliers .extend (doplot (
4098
- flier_x , flier_y , ** final_flierprops
4099
- ))
4053
+ fliers .append (do_plot (flier_x , flier_y , ** flier_kw ))
4100
4054
4101
4055
if manage_ticks :
4102
4056
axis_name = "x" if vert else "y"
0 commit comments