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

Skip to content

Bug restore boxplot defaults #3165

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 11, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 81 additions & 38 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import matplotlib.transforms as mtrans
from matplotlib.container import BarContainer, ErrorbarContainer, StemContainer
from matplotlib.axes._base import _AxesBase
from matplotlib.axes._base import _process_plot_format

iterable = cbook.iterable
is_string_like = cbook.is_string_like
Expand Down Expand Up @@ -2883,18 +2884,19 @@ def boxplot(self, x, notch=False, sym='b+', vert=True, whis=1.5,
meanline=False, showmeans=False, showcaps=True,
showbox=True, showfliers=True, boxprops=None, labels=None,
flierprops=None, medianprops=None, meanprops=None,
manage_xticks=True):
capprops=None, whiskerprops=None, manage_xticks=True):
"""
Make a box and whisker plot.

Call signature::

boxplot(x, notch=False, sym='b+', vert=True, whis=1.5,
boxplot(self, x, notch=False, sym='b+', vert=True, whis=1.5,
positions=None, widths=None, patch_artist=False,
bootstrap=None, usermedians=None, conf_intervals=None,
meanline=False, showmeans=False, showcaps=True,
showbox=True, showfliers=True, boxprops=None, labels=None,
flierprops=None, medianprops=None, meanprops=None)
flierprops=None, medianprops=None, meanprops=None,
capprops=None, whiskerprops=None, manage_xticks=True):

Make a box and whisker plot for each column of *x* or each
vector in sequence *x*. The box extends from the lower to
Expand Down Expand Up @@ -2990,6 +2992,12 @@ def boxplot(self, x, notch=False, sym='b+', vert=True, whis=1.5,
boxprops : dict or None (default)
If provided, will set the plotting style of the boxes

whiskerprops : dict or None (default)
If provided, will set the plotting style of the whiskers

capprops : dict or None (default)
If provided, will set the plotting style of the caps

flierprops : dict or None (default)
If provided, will set the plotting style of the fliers

Expand Down Expand Up @@ -3030,14 +3038,15 @@ def boxplot(self, x, notch=False, sym='b+', vert=True, whis=1.5,
"""
bxpstats = cbook.boxplot_stats(x, whis=whis, bootstrap=bootstrap,
labels=labels)
if sym == 'b+' and flierprops is None:
flierprops = dict(linestyle='none', marker='+',
markeredgecolor='blue')
if flierprops is None:
flierprops = dict(sym=sym)
else:
flierprops['sym'] = sym

# replace medians if necessary:
if usermedians is not None:
if (len(np.ravel(usermedians)) != len(bxpstats) or
np.shape(usermedians)[0] != len(bxpstats)):
np.shape(usermedians)[0] != len(bxpstats)):
medmsg = 'usermedians length not compatible with x'
raise ValueError(medmsg)
else:
Expand Down Expand Up @@ -3069,24 +3078,27 @@ def boxplot(self, x, notch=False, sym='b+', vert=True, whis=1.5,
boxprops=boxprops, flierprops=flierprops,
medianprops=medianprops, meanprops=meanprops,
meanline=meanline, showfliers=showfliers,
capprops=capprops, whiskerprops=whiskerprops,
manage_xticks=manage_xticks)
return artists

def bxp(self, bxpstats, positions=None, widths=None, vert=True,
patch_artist=False, shownotches=False, showmeans=False,
showcaps=True, showbox=True, showfliers=True,
boxprops=None, flierprops=None, medianprops=None,
meanprops=None, meanline=False, manage_xticks=True):
boxprops=None, whiskerprops=None, flierprops=None,
medianprops=None, capprops=None, meanprops=None,
meanline=False, manage_xticks=True):
"""
Drawing function for box and whisker plots.

Call signature::

bxp(bxpstats, positions=None, widths=None, vert=True,
bxp(self, bxpstats, positions=None, widths=None, vert=True,
patch_artist=False, shownotches=False, showmeans=False,
showcaps=True, showbox=True, showfliers=True,
boxprops=None, flierprops=None, medianprops=None,
meanprops=None, meanline=False, manage_xticks=True)
boxprops=None, whiskerprops=None, flierprops=None,
medianprops=None, capprops=None, meanprops=None,
meanline=False, manage_xticks=True):

Make a box and whisker plot for each column of *x* or each
vector in sequence *x*. The box extends from the lower to
Expand Down Expand Up @@ -3132,14 +3144,14 @@ def bxp(self, bxpstats, positions=None, widths=None, vert=True,
If True produces boxes with the Patch artist

shownotches : bool, default = False
If False (default), produces a rectangular box plot.
If True, will produce a notched box plot
If False (default), produces a rectangular box plot.
If True, will produce a notched box plot

showmeans : bool, default = False
If True, will toggle one the rendering of the means

showcaps : bool, default = True
If True, will toggle one the rendering of the caps
If True will toggle one the rendering of the caps

showbox : bool, default = True
If True, will toggle one the rendering of box
Expand All @@ -3150,8 +3162,14 @@ def bxp(self, bxpstats, positions=None, widths=None, vert=True,
boxprops : dict or None (default)
If provided, will set the plotting style of the boxes

whiskerprops : dict or None (default)
If provided, will set the plotting style of the whiskers

capprops : dict or None (default)
If provided, will set the plotting style of the caps

flierprops : dict or None (default)
If provided, will set the plotting style of the fliers
If provided will set the plotting style of the fliers

medianprops : dict or None (default)
If provided, will set the plotting style of the medians
Expand Down Expand Up @@ -3215,37 +3233,58 @@ def bxp(self, bxpstats, positions=None, widths=None, vert=True,
final_boxprops = dict(linestyle='solid', edgecolor='black',
facecolor='white', linewidth=1)
else:
final_boxprops = dict(linestyle='-', color='black', linewidth=1)
final_boxprops = dict(linestyle='-', color='blue')

if boxprops is not None:
final_boxprops.update(boxprops)

# other (cap, whisker) properties
if patch_artist:
otherprops = dict(
linestyle=linestyle_map[final_boxprops['linestyle']],
color=final_boxprops['edgecolor'],
linewidth=final_boxprops.get('linewidth', 1)
)
else:
otherprops = dict(linestyle=final_boxprops['linestyle'],
color=final_boxprops['color'],
linewidth=final_boxprops.get('linewidth', 1))
final_whiskerprops = dict(
linestyle='--',
color='blue',
)

# flier (outlier) properties
final_capprops = dict(
linestyle='-',
color='black',
)

if capprops is not None:
final_capprops.update(capprops)

if whiskerprops is not None:
final_whiskerprops.update(whiskerprops)

# set up the default flier properties
final_flierprops = dict(linestyle='none', marker='+',
markeredgecolor='blue')
markeredgecolor='b',
markerfacecolor='none')
# flier (outlier) properties
if flierprops is not None:
sym = flierprops.pop('sym', None)

# watch inverted logic, checks for non-default
# value of `sym`
if not (sym == '' or (sym is None)):
# process the symbol string
# discarded linestyle
_, marker, color = _process_plot_format(sym)
flierprops['marker'] = marker
flierprops['color'] = color
# assume that if color is passed in the user want
# filled symbol
flierprops['markeredgecolor'] = color
flierprops['markerfacecolor'] = color
final_flierprops.update(flierprops)

# median line properties
final_medianprops = dict(linestyle='-', color='blue')
final_medianprops = dict(linestyle='-', color='red')
if medianprops is not None:
final_medianprops.update(medianprops)

# mean (line or point) properties
if meanline:
final_meanprops = dict(linestyle='--', color='red')
final_meanprops = dict(linestyle='--', color='black')
else:
final_meanprops = dict(linestyle='none', markerfacecolor='red',
marker='s')
Expand Down Expand Up @@ -3313,11 +3352,9 @@ def dopatch(xs, ys, **kwargs):
if not self._hold:
self.cla()
holdStatus = self._hold

for pos, width, stats in zip(positions, widths, bxpstats):
# try to find a new label
datalabels.append(stats.get('label', pos))

# fliers coords
flier_x = np.ones(len(stats['fliers'])) * pos
flier_y = stats['fliers']
Expand Down Expand Up @@ -3365,13 +3402,17 @@ def dopatch(xs, ys, **kwargs):
boxes.extend(doplot(box_x, box_y, **final_boxprops))

# draw the whiskers
whiskers.extend(doplot(whisker_x, whiskerlo_y, **otherprops))
whiskers.extend(doplot(whisker_x, whiskerhi_y, **otherprops))
whiskers.extend(doplot(
whisker_x, whiskerlo_y, **final_whiskerprops
))
whiskers.extend(doplot(
whisker_x, whiskerhi_y, **final_whiskerprops
))

# maybe draw the caps:
if showcaps:
caps.extend(doplot(cap_x, cap_lo, **otherprops))
caps.extend(doplot(cap_x, cap_hi, **otherprops))
caps.extend(doplot(cap_x, cap_lo, **final_capprops))
caps.extend(doplot(cap_x, cap_hi, **final_capprops))

# draw the medians
medians.extend(doplot(med_x, med_y, **final_medianprops))
Expand All @@ -3390,7 +3431,9 @@ def dopatch(xs, ys, **kwargs):

# maybe draw the fliers
if showfliers:
fliers.extend(doplot(flier_x, flier_y, **final_flierprops))
fliers.extend(doplot(
flier_x, flier_y, **final_flierprops
))

# fix our axes/ticks up a little
if vert:
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/cbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -1948,7 +1948,7 @@ def _compute_conf_interval(data, med, iqr, bootstrap):

ncols = len(X)
if labels is None:
labels = [str(i) for i in range(ncols)]
labels = [str(i) for i in range(1, ncols+1)]
elif len(labels) != ncols:
raise ValueError("Dimensions of labels and X must be compatible")

Expand Down
Binary file modified lib/matplotlib/tests/baseline_images/test_axes/boxplot.pdf
Binary file not shown.
Binary file modified lib/matplotlib/tests/baseline_images/test_axes/boxplot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading