mgkit.plots.boxplot module

New in version 0.1.14.

Code related to boxplots

mgkit.plots.boxplot.add_significance_to_boxplot(sign_indices, ax, pos, box_vert=True, fontsize=16)[source]

New in version 0.1.16.

Add significance groups to boxplots

Parameters
  • sign_indices (iterable) – iterable in which each element is a tuple; each element of the tuple is the numerical index of the position of the significant boxplot

  • ax – an axis instance

  • pos (tuple) – the 2 values are the coordinates for the top line, and the the lowest bound for the whisker

  • box_vert (bool) – if the boxplot is vertical

  • fontsize (float) – size for the * (star)

mgkit.plots.boxplot.add_values_to_boxplot(dataframe, ax, plot_data, plot_order, data_colours=None, alpha=0.5, s=80, marker='o', linewidth=0.01, box_vert=False)[source]

New in version 0.1.13.

Changed in version 0.1.14: added box_vert parameter

Changed in version 0.1.16: changed default value for linewidth

Adds the values of a dataframe used in boxplot_dataframe() to the plot. linewidth must be higher than 0 if a marker like | is used.

A list of markers is available at this page

Warning

Contrary to boxplot_dataframe(), the boxplot default is horizontal (box_vert). The default will change in a later version.

Parameters
  • dataframe – dataframe with the values to plot

  • ax – an axis instance

  • plot_data – return value from boxplot_dataframe()

  • plot_order (iterable) – row order used to plot the boxes

  • data_colours (dict) – colors used for the values

  • alpha (float) – alpha value for the colour

  • s (int) – size of the marker drawn

  • marker (str) – one of the accepted matplotlib markers

  • linewidth (float) – width of the line used to draw the marker

  • box_vert (bool) – specify if the original boxplot is vertical or not

mgkit.plots.boxplot.boxplot_dataframe(dataframe, plot_order, ax, label_map=None, fonts=None, fill_box=True, colours=None, data_colours=None, box_vert=True, widths=0.5)[source]

New in version 0.1.7: To move from an all-in-one drawing to a more modular one.

Changed in version 0.1.13: added box_vert parameter

Changed in version 0.1.16: added widths parameter

The function draws a series of boxplots from a DataFrame object, whose order is directed by the iterable plot_order. The columns of each DataFrame row contains the values for each boxplot. An ax object is needed.

Parameters
  • dataframe – dataframe to plot

  • plot_order (iterable) – row order used to plot the boxes

  • ax – an axis instance

  • label_map (dict) – a map that converts the items in plot_order to a label used on the plot X ax

  • fonts (dict) – dictionary with properties for x axis labels, DEFAULT_BOXPLOT_FONTCONF is used by default

  • fill_box (bool) – if True each box is filled with the same colour of its outline

  • colours (dict) – dictionary with properties for each boxplot if data_colours is None, whi overrides box, whiskers and fliers. Defaults to DEFAULT_BOXPLOT_COLOURS

  • data_colours (dict) – dictionary of colours for each boxplot, a set of colours can be obtained using func:map_taxon_to_colours

  • box_vert (bool) – if False the boxplots are drawn horizontally

  • widths (float) – width (scalar or array) of the boxplots width(s)

Returns

the plot data; same as matplotlib boxplot function

mgkit.plots.boxplot.boxplot_dataframe_multindex(dataframe, axes, plot_order=None, label_map=None, fonts=None, fill_box=True, colours=None, data_colours=None, box_vert=True)[source]

New in version 0.1.13.

Todo

documentation

The function draws a series of boxplots from a DataFrame object, whose order is directed by the iterable plot_order. The columns of each DataFrame row contains the values for each boxplot. An axes object is needed.

Parameters
  • dataframe – dataframe to plot

  • plot_order (iterable) – row order used to plot the boxes

  • axes – an axes instance

  • label_map (dict) – a map that converts the items in plot_order to a label used on the plot X axes

  • fonts (dict) – dictionary with properties for x axis labels, DEFAULT_BOXPLOT_FONTCONF is used by default

  • fill_box (bool) – if True each box is filled with the same colour of its outline

  • colours (dict) – dictionary with properties for each boxplot if data_colours is None, whi overrides box, whiskers and fliers. Defaults to DEFAULT_BOXPLOT_COLOURS

  • data_colours (dict) – dictionary of colours for each boxplot, a set of colours can be obtained using func:map_taxon_to_colours

Returns

the plot data same as matplotlib boxplot function