Skip to content

Commit 7df0313

Browse files
phobsontacaswell
authored andcommitted
restored default boxplot style and respect for the sym kwarg
1 parent 1c89da9 commit 7df0313

File tree

11 files changed

+271
-189
lines changed

11 files changed

+271
-189
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 77 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2883,18 +2883,19 @@ def boxplot(self, x, notch=False, sym='b+', vert=True, whis=1.5,
28832883
meanline=False, showmeans=False, showcaps=True,
28842884
showbox=True, showfliers=True, boxprops=None, labels=None,
28852885
flierprops=None, medianprops=None, meanprops=None,
2886-
manage_xticks=True):
2886+
capprops=None, whiskerprops=None, manage_xticks=True):
28872887
"""
28882888
Make a box and whisker plot.
28892889
28902890
Call signature::
28912891
2892-
boxplot(x, notch=False, sym='b+', vert=True, whis=1.5,
2892+
boxplot(self, x, notch=False, sym='b+', vert=True, whis=1.5,
28932893
positions=None, widths=None, patch_artist=False,
28942894
bootstrap=None, usermedians=None, conf_intervals=None,
28952895
meanline=False, showmeans=False, showcaps=True,
28962896
showbox=True, showfliers=True, boxprops=None, labels=None,
2897-
flierprops=None, medianprops=None, meanprops=None)
2897+
flierprops=None, medianprops=None, meanprops=None,
2898+
capprops=None, whiskerprops=None, manage_xticks=True):
28982899
28992900
Make a box and whisker plot for each column of *x* or each
29002901
vector in sequence *x*. The box extends from the lower to
@@ -2914,7 +2915,7 @@ def boxplot(self, x, notch=False, sym='b+', vert=True, whis=1.5,
29142915
29152916
sym : str, default = 'b+'
29162917
The default symbol for flier points.
2917-
Enter an empty string ('') if you don't want to show fliers.
2918+
Enter an empty string ('') if you don't wantshow fliers.
29182919
29192920
vert : bool, default = False
29202921
If True (default), makes the boxes vertical.
@@ -2947,13 +2948,13 @@ def boxplot(self, x, notch=False, sym='b+', vert=True, whis=1.5,
29472948
An array or sequence whose first dimension (or length) is
29482949
compatible with *x*. This overrides the medians computed by
29492950
matplotlib for each element of *usermedians* that is not None.
2950-
When an element of *usermedians* == None, the median will be
2951-
computed by matplotlib as normal.
2951+
When an element of *usermedians* == None, the median will be
2952+
cted by matplb as normal.
29522953
29532954
conf_intervals : array-like or None (default)
29542955
Array or sequence whose first dimension (or length) is compatible
29552956
with *x* and whose second dimension is 2. When the current element
2956-
of *conf_intervals* is not None, the notch locations computed by
2957+
ofnf_intervals* is not None, the notch locations computed by
29572958
matplotlib are overridden (assuming notch is True). When an
29582959
element of *conf_intervals* is None, boxplot compute notches the
29592960
method specified by the other kwargs (e.g., *bootstrap*).
@@ -2990,6 +2991,12 @@ def boxplot(self, x, notch=False, sym='b+', vert=True, whis=1.5,
29902991
boxprops : dict or None (default)
29912992
If provided, will set the plotting style of the boxes
29922993
2994+
whiskerprops : dict or None (default)
2995+
If provided, will set the plotting style of the whiskers
2996+
2997+
capprops : dict or None (default)
2998+
If provided, will set the plotting style of the whiskers
2999+
29933000
flierprops : dict or None (default)
29943001
If provided, will set the plotting style of the fliers
29953002
@@ -3030,9 +3037,10 @@ def boxplot(self, x, notch=False, sym='b+', vert=True, whis=1.5,
30303037
"""
30313038
bxpstats = cbook.boxplot_stats(x, whis=whis, bootstrap=bootstrap,
30323039
labels=labels)
3033-
if sym == 'b+' and flierprops is None:
3034-
flierprops = dict(linestyle='none', marker='+',
3035-
markeredgecolor='blue')
3040+
if flierprops is None:
3041+
flierprops = dict(sym=sym)
3042+
else:
3043+
flierprops['sym'] = sym
30363044

30373045
# replace medians if necessary:
30383046
if usermedians is not None:
@@ -3069,24 +3077,27 @@ def boxplot(self, x, notch=False, sym='b+', vert=True, whis=1.5,
30693077
boxprops=boxprops, flierprops=flierprops,
30703078
medianprops=medianprops, meanprops=meanprops,
30713079
meanline=meanline, showfliers=showfliers,
3080+
capprops=capprops, whiskerprops=whiskerprops,
30723081
manage_xticks=manage_xticks)
30733082
return artists
30743083

30753084
def bxp(self, bxpstats, positions=None, widths=None, vert=True,
30763085
patch_artist=False, shownotches=False, showmeans=False,
30773086
showcaps=True, showbox=True, showfliers=True,
3078-
boxprops=None, flierprops=None, medianprops=None,
3079-
meanprops=None, meanline=False, manage_xticks=True):
3087+
boxprops=None, whiskerprops=None, flierprops=None,
3088+
medianprops=None, capprops=None, meanprops=None,
3089+
meanline=False, manage_xticks=True):
30803090
"""
30813091
Drawing function for box and whisker plots.
30823092
30833093
Call signature::
30843094
3085-
bxp(bxpstats, positions=None, widths=None, vert=True,
3095+
bxp(self, bxpstats, positions=None, widths=None, vert=True,
30863096
patch_artist=False, shownotches=False, showmeans=False,
30873097
showcaps=True, showbox=True, showfliers=True,
3088-
boxprops=None, flierprops=None, medianprops=None,
3089-
meanprops=None, meanline=False, manage_xticks=True)
3098+
boxprops=None, whiskerprops=None, flierprops=None,
3099+
medianprops=None, capprops=None, meanprops=None,
3100+
meanline=False, manage_xticks=True):
30903101
30913102
Make a box and whisker plot for each column of *x* or each
30923103
vector in sequence *x*. The box extends from the lower to
@@ -3132,14 +3143,14 @@ def bxp(self, bxpstats, positions=None, widths=None, vert=True,
31323143
If True produces boxes with the Patch artist
31333144
31343145
shownotches : bool, default = False
3135-
If False (default), produces a rectangular box plot.
3136-
If True, will produce a notched box plot
3146+
If False (default), produces a rectangular box plot.
3147+
If True, will produce a ed box plot
31373148
31383149
showmeans : bool, default = False
31393150
If True, will toggle one the rendering of the means
31403151
31413152
showcaps : bool, default = True
3142-
If True, will toggle one the rendering of the caps
3153+
If T will toggle one the rendering of the caps
31433154
31443155
showbox : bool, default = True
31453156
If True, will toggle one the rendering of box
@@ -3150,8 +3161,14 @@ def bxp(self, bxpstats, positions=None, widths=None, vert=True,
31503161
boxprops : dict or None (default)
31513162
If provided, will set the plotting style of the boxes
31523163
3164+
whiskerprops : dict or None (default)
3165+
If provided, will set the plotting style of the whiskers
3166+
3167+
capprops : dict or None (default)
3168+
If provided, will set the plotting style of the whiskers
3169+
31533170
flierprops : dict or None (default)
3154-
If provided, will set the plotting style of the fliers
3171+
If provi will set the plotting style of the fliers
31553172
31563173
medianprops : dict or None (default)
31573174
If provided, will set the plotting style of the medians
@@ -3215,37 +3232,52 @@ def bxp(self, bxpstats, positions=None, widths=None, vert=True,
32153232
final_boxprops = dict(linestyle='solid', edgecolor='black',
32163233
facecolor='white', linewidth=1)
32173234
else:
3218-
final_boxprops = dict(linestyle='-', color='black', linewidth=1)
3235+
final_boxprops = dict(linestyle='-', color='blue')
32193236

32203237
if boxprops is not None:
32213238
final_boxprops.update(boxprops)
32223239

32233240
# other (cap, whisker) properties
3224-
if patch_artist:
3225-
otherprops = dict(
3226-
linestyle=linestyle_map[final_boxprops['linestyle']],
3227-
color=final_boxprops['edgecolor'],
3228-
linewidth=final_boxprops.get('linewidth', 1)
3229-
)
3230-
else:
3231-
otherprops = dict(linestyle=final_boxprops['linestyle'],
3232-
color=final_boxprops['color'],
3233-
linewidth=final_boxprops.get('linewidth', 1))
3241+
final_whiskerprops = dict(
3242+
linestyle='--',
3243+
color='blue',
3244+
)
3245+
3246+
final_capprops = dict(
3247+
linestyle='-',
3248+
color='black',
3249+
)
3250+
3251+
if capprops is not None:
3252+
final_capprops.update(capprops)
3253+
3254+
if whiskerprops is not None:
3255+
final_whiskerprops.update(whiskerprops)
32343256

32353257
# flier (outlier) properties
3236-
final_flierprops = dict(linestyle='none', marker='+',
3237-
markeredgecolor='blue')
32383258
if flierprops is not None:
3259+
sym = flierprops.pop('sym', '')
3260+
3261+
if sym == '':
3262+
final_flierprops = dict(linestyle='none', marker='+',
3263+
markeredgecolor='b',
3264+
markerfacecolor='none')
3265+
else:
3266+
final_flierprops = dict(linestyle='none')
32393267
final_flierprops.update(flierprops)
3268+
else:
3269+
sym = ''
3270+
final_flierprops = dict(linestyle='none', marker='+',
3271+
markeredgecolor='b')
32403272

32413273
# median line properties
3242-
final_medianprops = dict(linestyle='-', color='blue')
3274+
final_medianprops = dict(linestyle='-', color='red')
32433275
if medianprops is not None:
32443276
final_medianprops.update(medianprops)
32453277

32463278
# mean (line or point) properties
32473279
if meanline:
3248-
final_meanprops = dict(linestyle='--', color='red')
3280+
final_meanprops = dict(linestyle='--', color='black')
32493281
else:
32503282
final_meanprops = dict(linestyle='none', markerfacecolor='red',
32513283
marker='s')
@@ -3365,13 +3397,17 @@ def dopatch(xs, ys, **kwargs):
33653397
boxes.extend(doplot(box_x, box_y, **final_boxprops))
33663398

33673399
# draw the whiskers
3368-
whiskers.extend(doplot(whisker_x, whiskerlo_y, **otherprops))
3369-
whiskers.extend(doplot(whisker_x, whiskerhi_y, **otherprops))
3400+
whiskers.extend(doplot(
3401+
whisker_x, whiskerlo_y,**final_whiskerprops
3402+
))
3403+
whiskers.extend(doplot(
3404+
whisker_x, whiskerhi_y,**final_whiskerprops
3405+
))
33703406

33713407
# maybe draw the caps:
33723408
if showcaps:
3373-
caps.extend(doplot(cap_x, cap_lo, **otherprops))
3374-
caps.extend(doplot(cap_x, cap_hi, **otherprops))
3409+
caps.extend(doplot(cap_x, cap_lo, **final_capprops))
3410+
caps.extend(doplot(cap_x, cap_hi, **final_capprops))
33753411

33763412
# draw the medians
33773413
medians.extend(doplot(med_x, med_y, **final_medianprops))
@@ -3390,7 +3426,9 @@ def dopatch(xs, ys, **kwargs):
33903426

33913427
# maybe draw the fliers
33923428
if showfliers:
3393-
fliers.extend(doplot(flier_x, flier_y, **final_flierprops))
3429+
fliers.extend(doplot(
3430+
flier_x, flier_y, sym, **final_flierprops
3431+
))
33943432

33953433
# fix our axes/ticks up a little
33963434
if vert:
Binary file not shown.
Loading

0 commit comments

Comments
 (0)