explore_spaghetti_plot

source

explore_spaghetti_plot(
    df,
    var,
    *,
    entity=None,
    time=None,
    overlay='mean',
    highlight=None,
    alpha=None,
    max_units=150,
    facet=None,
    sample_seed=0,
    title=None,
    subtitle=None,
)

Plot every unit’s trajectory of var over time, with a central-tendency overlay.

Parameters

Name Type Description Default
df pd.DataFrame Panel data frame. required
var str Numeric variable to plot. required
entity str | None Cross-sectional (unit) identifier. Defaults to the panel entity. None
time str | None Time identifier. Defaults to the panel time. None
overlay Literal['mean', 'median', 'none'] Bold overlay line: "mean" (default), "median" or "none". 'mean'
highlight Sequence[str] | None Units to draw in saturated colour on top of the faint backdrop. None
alpha float | None Opacity of the faint per-unit lines. Defaults to a sample-size-based value. None
max_units int | None Cap on the number of units drawn; above it a seeded sample is shown (highlighted units are always kept) and a warning reports how many were dropped. None draws all units. 150
facet str | None Optional grouping column; when given, draws one small-multiple panel per level. None
sample_seed int Seed for the unit subsample when max_units is exceeded. 0

Returns

Name Type Description
SpaghettiGraphResult df (plotted long frame), fig, n_units (in the data) and n_shown.

Examples

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_spaghetti_plot(df, var="log_gdp_pc").fig