publiplots.barplot

publiplots.barplot(data, x, y, hue=None, hatch=None, color=None, ax=None, title='', xlabel='', ylabel='', linewidth=None, capsize=None, alpha=None, figsize=None, palette=None, hatch_map=None, legend=True, legend_kws=None, errorbar='se', gap=0.1, order=None, hue_order=None, hatch_order=None, **kwargs)[source]

Create a publication-ready bar plot.

This function creates bar plots with optional grouping, error bars, and hatch patterns. Supports both simple and complex bar plots with side-by-side grouped bars.

Parameters:
  • data (DataFrame) – Input data.

  • x (str) – Column name for x-axis categories.

  • y (str) – Column name for y-axis values.

  • hue (str, optional) – Column name for color grouping (typically same as x for hatched bars).

  • hatch (str, optional) – Column name for splitting bars side-by-side with hatch patterns. When specified, creates grouped bars within each x category.

  • color (str, optional) – Fixed color for all bars (only used when hue is None). Overrides default color. Example: “#ff0000” or “red”.

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

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

  • xlabel (str, default="") – X-axis label. If empty and hatch is used, uses x column name.

  • ylabel (str, default="") – Y-axis label. If empty, uses y column name.

  • linewidth (float, default=1.0) – Width of bar edges.

  • capsize (float, default=0.0) – Width of error bar caps.

  • alpha (float, default=0.1) – Transparency of bar fill (0-1). Use 0 for outlined bars only.

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

  • palette (str, dict, or list, optional) – Color palette. Can be: - str: seaborn palette name or publiplots palette name - dict: mapping from hue values to colors - list: list of colors

  • hatch_map (dict, optional) – Mapping from hatch values to hatch patterns. Example: {“group1”: “”, “group2”: “///”, “group3”: “\"}

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

  • errorbar (str, default="se") – Error bar type: “se” (standard error), “sd” (standard deviation), “ci” (confidence interval), or None for no error bars.

  • gap (float, default=0.1) – Gap between bar groups (0-1).

  • order (list, optional) – Order of x/y-axis categories. If provided, determines bar order.

  • hue_order (list, optional) – Hue order. If provided, determines bar order within groups.

  • hatch_order (list, optional) – Order of hatch categories. If provided, determines bar order within groups.

  • **kwargs – Additional keyword arguments passed to seaborn.barplot().

Returns:

  • fig (Figure) – Matplotlib figure object.

  • ax (Axes) – Matplotlib axes object.

Return type:

Tuple[Figure, Axes]

Examples

Simple bar plot: >>> fig, ax = pp.barplot(data=df, x=”category”, y=”value”)

Bar plot with color groups: >>> fig, ax = pp.barplot(data=df, x=”category”, y=”value”, … hue=”group”, palette=”pastel”)

Bar plot with hatched bars and patterns: >>> fig, ax = pp.barplot( … data=df, x=”condition”, y=”measurement”, … hatch=”treatment”, hue=”condition”, … hatch_map={“control”: “”, “treated”: “///”}, … palette={“A”: “#75b375”, “B”: “#8e8ec1”} … )

See also

barplot_enrichment

Specialized bar plot for enrichment analysis