ehrapy.plot.sankey_diagram_time#
- ehrapy.plot.sankey_diagram_time(edata, *, var_name, layer, state_labels=None, node_width=20, node_padding=10, node_color=None, edge_color=None, label_position='right', show_values=True, title=None, width=600, height=400, **kwargs)[source]#
Create a Sankey diagram showing patient state transitions over time.
Each node represents a state at a specific time point, and flows show the number of patients transitioning between states. Visualizes how patients transition between different states (e.g. disease severity, treatment status) across consecutive time points.
- Parameters:
edata (
EHRData) – Central data object.var_name (
str) – Variable name from edata.var_names to visualizelayer (
str) – Name of the layer in edata.layers containing the feature data to visualize.state_labels (
dict[int,str] |None, default:None) – Mapping from numeric state values to readable labels. If None, state values will be displayed as strings of their numeric codes (e.g., “0”, “1”, “2”).node_width (
int|float, default:20) – Width of the nodes in the Sankey diagram.node_padding (
int|float, default:10) – Padding between nodes in the Sankey diagram.node_color (
str|None, default:None) – Color of the nodes. If None, default coloring is used.edge_color (
str|None, default:None) – Color of the edges. If None, default coloring is used.label_position (
str|None, default:'right') – Position of the labels on the nodes. Options are ‘left’, ‘right’, ‘outer’, or ‘inner’.show_values (
bool, default:True) – Whether to display the values on the edges.title (
str|None, default:None) – Title of the Sankey diagram.width (
int|None, default:600) – Width of the Sankey diagram.height (
int|None, default:400) – Height of the Sankey diagram.**kwargs – Additional styling options passed to
holoviews.element.sankey.Sankey.
- Return type:
Examples
>>> import ehrapy as ep >>> import ehrdata as ed >>> edata = ed.dt.ehrdata_blobs(base_timepoints=5, n_variables=1, n_observations=5, random_state=59) >>> edata.layers["tem_data"] = edata.layers["tem_data"].astype(int) >>> state_labels = {-2: "no", -3: "mild", -4: "moderate", -5: "severe", -6: "critical"} >>> ep.pl.sankey_diagram_time( ... edata, ... var_name="feature_0", ... layer="tem_data", ... state_labels=state_labels, ... )