explore_box_plot

source

explore_box_plot(
    df,
    by_var,
    var,
    *,
    time=None,
    order_by_mean=False,
    group_on_y=True,
    log=False,
    points='outliers',
    entity=None,
    title=None,
    subtitle=None,
)

Box plots of var across by_var groups, animated over time when available.

One box per group summarises the distribution (median, quartiles, whiskers). On a panel each period becomes a frame, stepped through by a play button and a time slider, with the value axis pinned so shifts are comparable; without a resolvable time id a single static set of boxes is drawn.

Parameters

Name Type Description Default
df pd.DataFrame Data frame containing the grouping factor, the numeric variable and (optionally) a time column. required
by_var str Grouping column. required
var str Numeric variable whose distribution is shown. required
time str | None Time identifier that drives the animation. Defaults to the panel time declared via :func:expdpy.set_panel; when neither is available the boxes are static. None
order_by_mean bool If True, groups are ordered by descending group mean. False
group_on_y bool If True (default), boxes are horizontal (groups on the y-axis). True
log bool Put the value axis on a log scale (default False). False
points Literal['outliers', 'all', 'suspectedoutliers'] | bool Which underlying points to overlay: "outliers" (default), "all", "suspectedoutliers" or False for none. 'outliers'
entity str | None Cross-sectional id (accepted for panel parity; only used to resolve the panel time). None

Returns

Name Type Description
BoxPlotResult df (the complete-case frame plotted) and fig (the Plotly box plot).

Examples

Regional inequality by continent, animated across the years:

import expdpy as ex
from expdpy.data import load_kuznets, load_kuznets_data_def

df = ex.set_labels(load_kuznets(), load_kuznets_data_def(), set_panel=True)
ex.explore_box_plot(df, "continent", "gini_regional", time="year").fig