publiplots.boxplot

publiplots.boxplot(data, x=None, y=None, hue=None, order=None, hue_order=None, orient=None, color=None, linecolor=None, palette=None, width=0.8, gap=0, whis=1.5, showcaps=False, fliersize=None, linewidth=None, alpha=None, figsize=None, ax=None, title='', xlabel='', ylabel='', legend=True, legend_kws=None, **kwargs)[source]

Create a publication-ready box plot.

This function creates box plots with transparent fill and opaque edges, following the publiplots visual style.

Parameters:
  • data (DataFrame) – Input data.

  • x (str, optional) – Column name for x-axis variable.

  • y (str, optional) – Column name for y-axis variable.

  • hue (str, optional) – Column name for color grouping.

  • order (list, optional) – Order for the categorical levels.

  • hue_order (list, optional) – Order for the hue levels.

  • orient (str, optional) – Orientation of the plot (‘v’ or ‘h’).

  • color (str, optional) – Fixed color for all boxes (only used when hue is None).

  • linecolor (str, optional) – Color of the box edges.

  • palette (str, dict, or list, optional) – Color palette for hue grouping.

  • width (float, default=0.8) – Width of the boxes.

  • gap (float, default=0) – Gap between boxes when using hue.

  • whis (float, default=1.5) – Proportion of IQR past low and high quartiles to extend whiskers.

  • showcaps (bool, default=False) – Whether to show the caps.

  • fliersize (float, optional) – Size of outlier markers.

  • linewidth (float, optional) – Width of box edges.

  • alpha (float, optional) – Transparency of box fill (0-1).

  • figsize (tuple, optional) – Figure size (width, height) if creating new figure.

  • ax (Axes, optional) – Matplotlib axes object. If None, creates new figure.

  • title (str, default="") – Plot title.

  • xlabel (str, default="") – X-axis label.

  • ylabel (str, default="") – Y-axis label.

  • legend (bool, default=True) – Whether to show the legend.

  • legend_kws (dict, optional) – Additional keyword arguments for legend.

  • **kwargs – Additional keyword arguments passed to seaborn.boxplot.

Returns:

  • fig (Figure) – Matplotlib figure object.

  • ax (Axes) – Matplotlib axes object.

Return type:

Tuple[Figure, Axes]

Examples

Simple box plot:

>>> import publiplots as pp
>>> fig, ax = pp.boxplot(data=df, x="category", y="value")

Box plot with hue grouping:

>>> fig, ax = pp.boxplot(
...     data=df, x="category", y="value", hue="group"
... )