Utilities

Summary Helpers

get_summary_stats

plotnine_extra.get_summary_stats(data, columns=None, type='common', groupvars=None)[source]

Compute summary statistics for one or more numeric columns.

Parameters:
  • data (DataFrame) – Input data.

  • columns (str or list of str, optional) – Numeric columns to summarise. If None all numeric columns are used.

  • type (str, default "common") – Profile of statistics. One of "common", "robust", "five_number", "mean_sd", "mean_se", "mean_ci", "median_iqr", "median_mad", "median_range", "quantile" or "full".

  • groupvars (str or list of str, optional) – Grouping columns. If supplied, the summary is computed within each group.

Return type:

pd.DataFrame

desc_statby

plotnine_extra.desc_statby(data, measurevar, groupvars)[source]

Per-group descriptive statistics for measurevar.

Returns one row per group with columns length, min, max, median, mean, iqr, mad, sd, se and ci.

Parameters:
  • data (pd.DataFrame)

  • measurevar (str)

  • groupvars (str | Sequence[str])

Return type:

pd.DataFrame

add_summary

plotnine_extra.add_summary(plot, fun='mean_se', error_plot='pointrange', color='black', fill='white', size=1.0, width=None, shape='o', linetype='solid', show_legend=False, **kwargs)[source]

Add a summary layer to an existing ggplot object.

Parameters:
  • plot (ggplot) – The plot to add the layer to.

  • fun (str or callable, default "mean_se") – Either a name from the ggpubr fun.data family ("mean_se", "mean_sd", "mean_ci", "median_iqr", …) or a callable returning a dict with y, ymin and ymax.

  • error_plot (str, default "pointrange") – Geom to use. One of "pointrange", "linerange", "crossbar", "errorbar", "upper_errorbar", "lower_errorbar", "upper_pointrange", "lower_pointrange".

  • color (str)

  • fill (str)

  • size (float)

  • width (float | None)

  • shape (str | int)

  • linetype (str)

  • show_legend (bool)

Summary Functions

mean_ci

plotnine_extra.mean_ci(x, ci=0.95)[source]

Return the mean and confidence-interval bounds.

Parameters:
  • x (array-like) – Input values.

  • ci (float, default 0.95) – Confidence level (between 0 and 1).

Return type:

dict

mean_sd

plotnine_extra.mean_sd(x, mult=1.0)[source]

Return the mean and mean ± mult * sd.

Parameters:
  • x (array-like) – Input values.

  • mult (float, default 1.0) – Standard-deviation multiplier.

Return type:

dict

mean_se

plotnine_extra.mean_se_(x, mult=1.0)[source]

Return the mean and mean ± mult * se.

The trailing suffix mirrors the R name to avoid clashing with Python’s mean builtins.

Parameters:

mult (float)

Return type:

dict

mean_range

plotnine_extra.mean_range(x)[source]

Return the mean and mean ± (max - min).

Matches ggpubr’s definition where range = max - min is applied symmetrically around the mean rather than using the raw min / max bounds.

Return type:

dict

median_iqr

plotnine_extra.median_iqr(x, mult=1.0)[source]

Return the median and median ± mult * IQR.

Parameters:

mult (float)

Return type:

dict

median_mad

plotnine_extra.median_mad(x, mult=1.0)[source]

Return the median and median ± mult * MAD.

The MAD (median absolute deviation) is scaled by the usual consistency constant 1.4826.

Parameters:

mult (float)

Return type:

dict

median_range

plotnine_extra.median_range(x)[source]

Return the median and median ± (max - min).

Matches ggpubr’s convention where range = max - min is applied symmetrically around the median rather than using the raw min / max bounds.

Return type:

dict

median_q1q3

plotnine_extra.median_q1q3(x)[source]

Return the median and the first / third quartiles.

Return type:

dict

median_hilow

plotnine_extra.median_hilow_(x, conf_int=0.95)[source]

Return the median and percentile-based confidence bounds.

Matches ggpubr’s definition: ymin = quantile(x, (1 - ci) / 2), ymax = quantile(x, (1 + ci) / 2).

Note: this differs from Hmisc::smedian.hilow, which uses an order-statistic interval. ggpubr deliberately uses the simpler percentile form; plotnine-extra follows suit.

Parameters:

conf_int (float)

Return type:

dict