ehrapy.plot.kaplan_meier#
- ehrapy.plot.kaplan_meier(kmfs, *, display_survival_statistics=False, ci_alpha=None, ci_force_lines=None, ci_show=None, ci_legend=None, at_risk_counts=None, color=None, grid=False, xlim=None, ylim=None, xlabel=None, ylabel=None, width=600, height=400, title=None)[source]#
Plots a pretty figure of the Fitted KaplanMeierFitter model.
See also:
KaplanMeierFitter.- Parameters:
kmfs (
Sequence[KaplanMeierFitter]) – Iterables of fitted KaplanMeierFitter objects.display_survival_statistics (
bool, default:False) – Whether to show survival statistics in a table below the plot.ci_alpha (
list[float] |None, default:None) – The transparency level of the confidence interval. If more than one kmfs, this should be a list.ci_force_lines (
list[bool] |None, default:None) – Force the confidence intervals to be line plots (versus default shaded areas). If more than one kmfs, this should be a list.ci_show (
list[bool] |None, default:None) – Show confidence intervals. If more than one kmfs, this should be a list.ci_legend (
list[bool] |None, default:None) – If ci_force_lines is True, this is a boolean flag to add the lines’ labels to the legend. If more than one kmfs, this should be a list.at_risk_counts (
list[bool] |None, default:None) – Show group sizes at time points. If more than one kmfs, this should be a list.color (
list[str|None] |None, default:None) – List of colors for each kmf. If more than one kmfs, this should be a list.grid (
bool|None, default:False) – If True, plot grid lines.xlim (
tuple[float,float] |None, default:None) – Set the x-axis view limits.ylim (
tuple[float,float] |None, default:None) – Set the y-axis view limits.title (
str|None, default:None) – Set the title of the plot.
- Return type:
Examples
>>> import ehrdata as ed >>> import ehrapy as ep >>> import numpy as np >>> edata = ed.dt.mimic_2() >>> edata[:, ["censor_flg"]].X = np.where( ... edata[:, ["censor_flg"]].X == 0, 1, 0 ... ) # MIMIC-II uses 0=death while KaplanMeierFitter expects True=death >>> kmf = ep.tl.kaplan_meier(edata, "mort_day_censored", "censor_flg") >>> ep.pl.kaplan_meier( ... [kmf], color=["r"], xlim=(0, 700), ylim=(0, 1), xlabel="Days", ylabel="Proportion Survived", show=True ... )