# skbio.draw.distributions.boxplots¶

skbio.draw.distributions.boxplots(distributions, x_values=None, x_tick_labels=None, title=None, x_label=None, y_label=None, x_tick_labels_orientation='vertical', y_min=None, y_max=None, whisker_length=1.5, box_width=0.5, box_colors=None, figure_width=None, figure_height=None, legend=None)[source]

Generate a figure with a boxplot for each distribution.

Parameters: distributions: list of lists List of distributions. x_values : list of numbers, optional List indicating where each boxplot should be placed. Must be the same length as distributions if provided. x_tick_labels : list of str, optional List of x-axis tick labels. title : str, optional Title of the plot. x_label : str, optional x-axis label. y_label : str, optional y-axis label. x_tick_labels_orientation : {‘vertical’, ‘horizontal’} Orientation of the x-axis labels. y_min : scalar, optional Minimum value of the y-axis. If None, uses matplotlib’s autoscale. y_max : scalar, optional Maximum value of the y-axis. If None, uses matplotlib’s autoscale. whisker_length : scalar, optional Length of the whiskers as a function of the IQR. For example, if 1.5, the whiskers extend to 1.5 * IQR. Anything outside of that range is treated as an outlier. box_width : scalar, optional Width of each box in plot units. box_colors : str, tuple, or list of colors, optional Either a matplotlib-compatible string or tuple that indicates the color to be used for every boxplot, or a list of colors to color each boxplot individually. If None, boxes will be the same color as the plot background. If a list of colors is provided, a color must be provided for each boxplot. Can also supply None instead of a color, which will color the box the same color as the plot background. figure_width : scalar, optional Width of the plot figure in inches. If not provided, will default to matplotlib’s default figure width. figure_height : scalar, optional Height of the plot figure in inches. If not provided, will default to matplotlib’s default figure height. legend : tuple or list, optional Two-element tuple or list that contains a list of valid matplotlib colors as the first element and a list of labels (strings) as the second element. The lengths of the first and second elements must be the same. If None, a legend will not be plotted. matplotlib.figure.Figure Figure containing a boxplot for each distribution.

See also

matplotlib.pyplot.boxplot, scipy.stats.ttest_ind

Notes

This is a convenience wrapper around matplotlib’s boxplot function that allows for coloring of boxplots and legend generation.

Examples

Create a plot with two boxplots:

>>> from skbio.draw.distributions import boxplots
>>> fig = boxplots([[2, 2, 1, 3, 4, 4.2, 7], [0, -1, 4, 5, 6, 7]])


Plot three distributions with custom colors and labels:

>>> from skbio.draw.distributions import boxplots
>>> fig = boxplots(
...     [[2, 2, 1, 3], [0, -1, 0, 0.1, 0.3], [4, 5, 6, 3]],
...     x_tick_labels=('Control', 'Treatment 1', 'Treatment 2'),
...     box_colors=('green', 'blue', 'red'))