Box Plot

class MatPlus.BoxPlot.BoxPlot(data, notch=False, symbol='b', vert=True, whisker_length=1.5, width=3, height=3, title=None, xlabel=None, ylabel=None)[source]

A class for creating box plots with customizable properties.

The BoxPlot class provides a simplified interface for creating box plots with options for notches, outlier symbols, and orientation.

Parameters:
  • data (array-like) – The data to be plotted.

  • notch (bool, optional) – Whether to draw a notch to indicate the confidence interval around the median. Default is False.

  • symbol (str, optional) – The symbol for outliers. Default is “b”.

  • vert (bool, optional) – Whether to draw the box plot vertically. Default is True.

  • whisker_length (float, optional) – The length of the whiskers as a multiple of the interquartile range (IQR). Default is 1.5.

  • width (float, optional) – The width of the plot. Default is 3. Effects auto ticks.

  • height (float, optional) – The height of the plot. Default is 3. Effects auto ticks.

  • title (str, optional) – The title of the plot. Default is None.

  • xlabel (str, optional) – The x-axis label. Default is None.

  • ylabel (str, optional) – The y-axis label. Default is None.

Examples

>>> # Basic box plot
>>> data = [1, 2, 2, 3, 3, 3, 4, 4, 5, 6]
>>> box = BoxPlot(data)
>>> box.plot()
>>> # Box plot with notches
>>> box = BoxPlot(data, notch=True)
>>> box.plot()
>>> # Horizontal box plot with custom outlier symbols
>>> box = BoxPlot(data, vert=False, symbol="r*")
>>> box.plot()
median()[source]

Calculate the median of the data.

Returns:

The median value of the dataset.

Return type:

float

outliers()[source]

Identify outliers using the whisker*IQR rule.

Returns:

A list of data points identified as outliers.

Return type:

list

plot()[source]

Create and display the box plot.

This method creates a matplotlib figure and plots the box plot with the specified properties. It applies settings such as orientation, notches, and outlier symbols as configured during initialization.

Returns:

The plot is displayed but not returned.

Return type:

None

quartiles()[source]

Calculate the first and third quartiles of the data.

Returns:

A tuple containing (Q1, Q3) values.

Return type:

tuple