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

Skip to content

Commit d29bcd7

Browse files
committed
ENH: added remaining bxp kwargs to boxplot
1 parent d8da483 commit d29bcd7

1 file changed

Lines changed: 65 additions & 18 deletions

File tree

lib/matplotlib/axes/_axes.py

Lines changed: 65 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2789,7 +2789,10 @@ def xywhere(xs, ys, mask):
27892789

27902790
def boxplot(self, x, notch=False, sym='b+', vert=True, whis=1.5,
27912791
positions=None, widths=None, patch_artist=False,
2792-
bootstrap=None, usermedians=None, conf_intervals=None):
2792+
bootstrap=None, usermedians=None, conf_intervals=None,
2793+
meanline=False, showmeans=False, showcaps=True,
2794+
showbox=True, showfliers=True, boxprops=None, labels=None,
2795+
flierprops=None, medianprops=None, meanprops=None):
27932796
"""
27942797
Make a box and whisker plot.
27952798
@@ -2822,10 +2825,18 @@ def boxplot(self, x, notch=False, sym='b+', vert=True, whis=1.5,
28222825
If True (default), makes the boxes vertical.
28232826
If False, makes horizontal boxes.
28242827
2825-
*whis* : [ default 1.5 ]
2826-
Defines the length of the whiskers as a function of the inner
2827-
quartile range. They extend to the most extreme data point
2828-
within ( ``whis*(75%-25%)`` ) data range.
2828+
*whis* : [ float | string | or sequence (default = 1.5) ]
2829+
As a float, determines the reach of the whiskers past the first
2830+
and third quartiles (e.g., Q3 + whis*IQR, IQR = interquartile
2831+
range, Q3-Q1). Beyond the whiskers, data are considered outliers
2832+
and are plotted as individual points. Set this to an unreasonably
2833+
high value to force the whiskers to show the min and max values.
2834+
Alternatively, set this to an ascending sequence of percentile
2835+
(e.g., [5, 95]) to set the whiskers at specific percentiles of
2836+
the data. Finally, can *whis* be the string 'range' to force the
2837+
whiskers to the min and max of the data. In the edge case that
2838+
the 25th and 75th percentiles are equivalent, *whis* will be
2839+
automatically set to 'range'.
28292840
28302841
*bootstrap* : [ *None* (default) | integer ]
28312842
Specifies whether to bootstrap the confidence intervals
@@ -2861,10 +2872,44 @@ def boxplot(self, x, notch=False, sym='b+', vert=True, whis=1.5,
28612872
default is 0.5, or ``0.15*(distance between extreme positions)``
28622873
if that is smaller.
28632874
2875+
*labels* : [ sequence | None (default) ]
2876+
Labels for each dataset. Length must be compatible with
2877+
dimensions of *x*
2878+
28642879
*patch_artist* : [ False (default) | True ]
28652880
If False produces boxes with the Line2D artist
28662881
If True produces boxes with the Patch artist
28672882
2883+
*showmeans* : [ False (default) | True ]
2884+
If True, will toggle one the rendering of the means
2885+
2886+
*showcaps* : [ False | True (default) ]
2887+
If True, will toggle one the rendering of the caps
2888+
2889+
*showbox* : [ False | True (default) ]
2890+
If True, will toggle one the rendering of box
2891+
2892+
*showfliers* : [ False | True (default) ]
2893+
If True, will toggle one the rendering of the fliers
2894+
2895+
*boxprops* : [ dict | None (default) ]
2896+
If provided, will set the plotting style of the boxes
2897+
2898+
*flierprops* : [ dict | None (default) ]
2899+
If provided, will set the plotting style of the fliers
2900+
2901+
*medianprops* : [ dict | None (default) ]
2902+
If provided, will set the plotting style of the medians
2903+
2904+
*meanprops* : [ dict | None (default) ]
2905+
If provided, will set the plotting style of the means
2906+
2907+
*meanline* : [ False (default) | True ]
2908+
If True (and *showmeans* is True), will try to render the mean
2909+
as a line spanning the full width of the box according to
2910+
*meanprops*. Not recommended if *shownotches* is also True.
2911+
Otherwise, means will be shown as points.
2912+
28682913
Returns a dictionary mapping each component of the boxplot
28692914
to a list of the :class:`matplotlib.lines.Line2D`
28702915
instances created. That dictionary has the following keys
@@ -2884,12 +2929,11 @@ def boxplot(self, x, notch=False, sym='b+', vert=True, whis=1.5,
28842929
28852930
.. plot:: pyplots/boxplot_demo.py
28862931
"""
2887-
bxpstats = cbook.boxplot_stats(x, whis=whis, bootstrap=bootstrap)
2888-
if sym == 'b+':
2932+
bxpstats = cbook.boxplot_stats(x, whis=whis, bootstrap=bootstrap,
2933+
labels=labels)
2934+
if sym == 'b+' and flierprops is None:
28892935
flierprops = dict(linestyle='none', marker='+',
28902936
markeredgecolor='blue')
2891-
else:
2892-
flierprops = sym
28932937

28942938
# replace medians if necessary:
28952939
if usermedians is not None:
@@ -2920,10 +2964,11 @@ def boxplot(self, x, notch=False, sym='b+', vert=True, whis=1.5,
29202964

29212965
artists = self.bxp(bxpstats, positions=positions, widths=widths,
29222966
vert=vert, patch_artist=patch_artist,
2923-
shownotches=notch, showmeans=False,
2924-
showcaps=True, boxprops=None,
2925-
flierprops=flierprops, medianprops=None,
2926-
meanprops=None, meanline=False)
2967+
shownotches=notch, showmeans=showmeans,
2968+
showcaps=showcaps, showbox=showbox,
2969+
boxprops=boxprops, flierprops=flierprops,
2970+
medianprops=medianprops, meanprops=meanprops,
2971+
meanline=meanline, showfliers=showfliers)
29272972
return artists
29282973

29292974
def bxp(self, bxpstats, positions=None, widths=None, vert=True,
@@ -3059,18 +3104,20 @@ def bxp(self, bxpstats, positions=None, widths=None, vert=True,
30593104
if boxprops is None:
30603105
if patch_artist:
30613106
boxprops = dict(linestyle='solid', edgecolor='black',
3062-
facecolor='white')
3107+
facecolor='white', linewidth=1)
30633108
else:
3064-
boxprops = dict(linestyle='-', color='black')
3109+
boxprops = dict(linestyle='-', color='black', linewidth=1)
30653110

30663111
if patch_artist:
30673112
otherprops = dict(
3068-
linestyle=linestyle_map[boxprops['linestyle']],
3069-
color=boxprops['edgecolor']
3113+
linestyle=linestyle_map[boxprops['linestyle']],
3114+
color=boxprops['edgecolor'],
3115+
linewidth=boxprops.get('linewidth', 1)
30703116
)
30713117
else:
30723118
otherprops = dict(linestyle=boxprops['linestyle'],
3073-
color=boxprops['color'])
3119+
color=boxprops['color'],
3120+
linewidth=boxprops.get('linewidth', 1))
30743121

30753122
if flierprops is None:
30763123
flierprops = dict(linestyle='none', marker='+',

0 commit comments

Comments
 (0)