Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e1cb5d2

Browse files
committed
Further factor out rcdefaults application in bxp().
1 parent 47d75f2 commit e1cb5d2

File tree

1 file changed

+25
-57
lines changed

1 file changed

+25
-57
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 25 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -3884,70 +3884,38 @@ def bxp(self, bxpstats, positions=None, widths=None, vert=True,
38843884
zorder = mlines.Line2D.zorder
38853885

38863886
zdelta = 0.1
3887+
3888+
def with_rcdefaults(subkey, explicit, zdelta=0):
3889+
d = {k.split('.')[-1]: v for k, v in rcParams.items()
3890+
if k.startswith(f'boxplot.{subkey}')}
3891+
d['zorder'] = zorder + zdelta
3892+
if explicit is not None:
3893+
d.update(explicit)
3894+
return d
3895+
38873896
# box properties
3888-
final_boxprops = dict(
3889-
linestyle=rcParams['boxplot.boxprops.linestyle'],
3890-
linewidth=rcParams['boxplot.boxprops.linewidth'],
3891-
)
38923897
if patch_artist:
3893-
final_boxprops.update(
3898+
final_boxprops = dict(
3899+
linestyle=rcParams['boxplot.boxprops.linestyle'],
3900+
linewidth=rcParams['boxplot.boxprops.linewidth'],
38943901
edgecolor=rcParams['boxplot.boxprops.color'],
38953902
facecolor=('white' if rcParams['_internal.classic_mode'] else
38963903
rcParams['patch.facecolor']),
3904+
zorder=zorder,
38973905
)
3906+
if boxprops is not None:
3907+
final_boxprops.update(boxprops)
38983908
else:
3899-
final_boxprops.update(
3900-
color=rcParams['boxplot.boxprops.color'],
3901-
)
3902-
3903-
final_boxprops['zorder'] = zorder
3904-
if boxprops is not None:
3905-
final_boxprops.update(boxprops)
3906-
3907-
# whisker properties
3908-
final_whiskerprops = {
3909-
k.split('.')[-1]: v for k, v in rcParams.items()
3910-
if k.startswith('boxplot.whiskerprops')
3911-
}
3912-
final_whiskerprops['zorder'] = zorder
3913-
if whiskerprops is not None:
3914-
final_whiskerprops.update(whiskerprops)
3915-
# cap properties
3916-
final_capprops = {
3917-
k.split('.')[-1]: v for k, v in rcParams.items()
3918-
if k.startswith('boxplot.capprops')
3919-
}
3920-
final_capprops['zorder'] = zorder
3921-
if capprops is not None:
3922-
final_capprops.update(capprops)
3923-
# flier properties
3924-
final_flierprops = {
3925-
k.split('.')[-1]: v for k, v in rcParams.items()
3926-
if k.startswith('boxplot.flierprops')
3927-
}
3928-
final_flierprops['zorder'] = zorder
3929-
if flierprops is not None:
3930-
final_flierprops.update(flierprops)
3931-
# median line properties
3932-
final_medianprops = {
3933-
k.split('.')[-1]: v for k, v in rcParams.items()
3934-
if k.startswith('boxplot.medianprops')
3935-
}
3936-
final_medianprops['zorder'] = zorder + zdelta
3937-
if medianprops is not None:
3938-
final_medianprops.update(medianprops)
3939-
# mean (line or point) properties
3940-
final_meanprops = {
3941-
k.split('.')[-1]: v for k, v in rcParams.items()
3942-
if k.startswith('boxplot.meanprops')
3943-
}
3944-
if meanline:
3945-
final_meanprops['marker'] = ''
3946-
else:
3947-
final_meanprops['linestyle'] = ''
3948-
final_meanprops['zorder'] = zorder + zdelta
3949-
if meanprops is not None:
3950-
final_meanprops.update(meanprops)
3909+
final_boxprops = with_rcdefaults('boxprops', boxprops)
3910+
final_whiskerprops = with_rcdefaults('whiskerprops', whiskerprops)
3911+
final_capprops = with_rcdefaults('capprops', capprops)
3912+
final_flierprops = with_rcdefaults('flierprops', flierprops)
3913+
final_medianprops = with_rcdefaults('medianprops', medianprops, zdelta)
3914+
final_meanprops = with_rcdefaults('meanprops', meanprops, zdelta)
3915+
removed_prop = 'marker' if meanline else 'linestyle'
3916+
# Only remove the property if it's not set explicitly as a parameter.
3917+
if meanprops is None or removed_prop not in meanprops:
3918+
final_meanprops[removed_prop] = ''
39513919

39523920
def to_vc(xs, ys):
39533921
# convert arguments to verts and codes, append (0, 0) (ignored).

0 commit comments

Comments
 (0)