publiplots.swarmplot

publiplots.swarmplot(data, x=None, y=None, hue=None, order=None, hue_order=None, dodge=False, orient=None, color=None, palette=None, size=5, edgecolor=None, linewidth=None, hue_norm=None, alpha=None, figsize=None, ax=None, title='', xlabel='', ylabel='', legend=True, legend_kws=None, **kwargs)[source]

Create a publication-ready swarm plot.

This function creates swarm 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.

  • dodge (bool, default=False) – Whether to separate points by hue along the categorical axis.

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

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

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

  • size (float, default=5) – Size of the markers.

  • edgecolor (str, optional) – Color for marker edges. If None, uses face color.

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

  • hue_norm (tuple or Normalize, optional) – Normalization for continuous hue variable.

  • alpha (float, optional) – Transparency of marker 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.swarmplot.

Returns:

  • fig (Figure) – Matplotlib figure object.

  • ax (Axes) – Matplotlib axes object.

Return type:

Tuple[Figure, Axes]

Examples

Simple swarm plot:

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

Swarm plot with hue grouping:

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