Skip to content

Commit 4234f0f

Browse files
committed
BUG : fix handling of flierprop by boxplot
- moved logic to parse sym from bxp -> boxplot - restored documented behavior with `sym=''` - change default value of sym from 'b+' -> None - should not be visible from outside as default behavior remains the same closes #3459
1 parent d10e26e commit 4234f0f

File tree

2 files changed

+38
-22
lines changed

2 files changed

+38
-22
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2883,7 +2883,7 @@ def xywhere(xs, ys, mask):
28832883

28842884
return errorbar_container # (l0, caplines, barcols)
28852885

2886-
def boxplot(self, x, notch=False, sym='b+', vert=True, whis=1.5,
2886+
def boxplot(self, x, notch=False, sym=None, vert=True, whis=1.5,
28872887
positions=None, widths=None, patch_artist=False,
28882888
bootstrap=None, usermedians=None, conf_intervals=None,
28892889
meanline=False, showmeans=False, showcaps=True,
@@ -2919,9 +2919,11 @@ def boxplot(self, x, notch=False, sym='b+', vert=True, whis=1.5,
29192919
If False, produces a rectangular box plot.
29202920
If True, will produce a notched box plot
29212921
2922-
sym : str, default = 'b+'
2922+
sym : str or None, default = None
29232923
The default symbol for flier points.
29242924
Enter an empty string ('') if you don't want to show fliers.
2925+
If `None`, then the fliers default to 'b+' If you want more
2926+
control use the fliersprop kwarg.
29252927
29262928
vert : bool, default = False
29272929
If True (default), makes the boxes vertical.
@@ -3043,10 +3045,39 @@ def boxplot(self, x, notch=False, sym='b+', vert=True, whis=1.5,
30433045
"""
30443046
bxpstats = cbook.boxplot_stats(x, whis=whis, bootstrap=bootstrap,
30453047
labels=labels)
3048+
# make sure we have a dictionary
30463049
if flierprops is None:
3047-
flierprops = dict(sym=sym)
3048-
else:
3049-
flierprops['sym'] = sym
3050+
flierprops = dict()
3051+
# if non-default sym value, put it into the flier dictionary
3052+
# the logic for providing the default symbol ('b+') now lives
3053+
# in bxp in the initial value of final_flierprops
3054+
# handle all of the `sym` related logic here so we only have to pass
3055+
# on the flierprops dict.
3056+
if sym is not None:
3057+
# no-flier case, which should really be done with
3058+
# 'showfliers=False' but none-the-less deal with it to keep back
3059+
# compatibility
3060+
if sym == '':
3061+
# blow away existing dict and make one for invisible markers
3062+
flierprops = dict(linestyle='none', marker='',
3063+
markeredgecolor='none',
3064+
markerfacecolor='none')
3065+
# now process the symbol string
3066+
else:
3067+
# process the symbol string
3068+
# discarded linestyle
3069+
_, marker, color = _process_plot_format(sym)
3070+
# if we have a marker, use it
3071+
if marker is not None:
3072+
flierprops['marker'] = marker
3073+
# if we have a color, use it
3074+
if color is not None:
3075+
flierprops['color'] = color
3076+
# assume that if color is passed in the user want
3077+
# filled symbol, if the users want more control use
3078+
# flierprops
3079+
flierprops['markeredgecolor'] = color
3080+
flierprops['markerfacecolor'] = color
30503081

30513082
# replace medians if necessary:
30523083
if usermedians is not None:
@@ -3288,24 +3319,9 @@ def bxp(self, bxpstats, positions=None, widths=None, vert=True,
32883319
final_flierprops = dict(linestyle='none', marker='+',
32893320
markeredgecolor='b',
32903321
markerfacecolor='none')
3322+
32913323
# flier (outlier) properties
32923324
if flierprops is not None:
3293-
sym = flierprops.pop('sym', None)
3294-
3295-
# watch inverted logic, checks for non-default
3296-
# value of `sym`
3297-
if not (sym == '' or (sym is None)):
3298-
# process the symbol string
3299-
# discarded linestyle
3300-
_, marker, color = _process_plot_format(sym)
3301-
if marker is not None:
3302-
flierprops['marker'] = marker
3303-
if color is not None:
3304-
flierprops['color'] = color
3305-
# assume that if color is passed in the user want
3306-
# filled symbol
3307-
flierprops['markeredgecolor'] = color
3308-
flierprops['markerfacecolor'] = color
33093325
final_flierprops.update(flierprops)
33103326

33113327
# median line properties

lib/matplotlib/pyplot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2611,7 +2611,7 @@ def broken_barh(xranges, yrange, hold=None, **kwargs):
26112611
# This function was autogenerated by boilerplate.py. Do not edit as
26122612
# changes will be lost
26132613
@_autogen_docstring(Axes.boxplot)
2614-
def boxplot(x, notch=False, sym='b+', vert=True, whis=1.5, positions=None,
2614+
def boxplot(x, notch=False, sym=None, vert=True, whis=1.5, positions=None,
26152615
widths=None, patch_artist=False, bootstrap=None, usermedians=None,
26162616
conf_intervals=None, meanline=False, showmeans=False, showcaps=True,
26172617
showbox=True, showfliers=True, boxprops=None, labels=None,

0 commit comments

Comments
 (0)