plotting¶

lifelines.plotting.
add_at_risk_counts
(*fitters, **kwargs)¶ Add counts showing how many individuals were at risk at each time point in survival/hazard plots.
Parameters: fitters – One or several fitters, for example KaplanMeierFitter, NelsonAalenFitter, etc… Returns: The axes which was used. Return type: ax Examples
>>> # First train some fitters and plot them >>> fig = plt.figure() >>> ax = plt.subplot(111) >>> >>> f1 = KaplanMeierFitter() >>> f1.fit(data) >>> f1.plot(ax=ax) >>> >>> f2 = KaplanMeierFitter() >>> f2.fit(data) >>> f2.plot(ax=ax) >>> >>> # There are equivalent >>> add_at_risk_counts(f1, f2) >>> add_at_risk_counts(f1, f2, ax=ax, fig=fig) >>> >>> # This overrides the labels >>> add_at_risk_counts(f1, f2, labels=['fitter one', 'fitter two']) >>> >>> # This hides the labels >>> add_at_risk_counts(f1, f2, labels=None)

lifelines.plotting.
plot_lifetimes
(durations, event_observed=None, entry=None, left_truncated=False, sort_by_duration=True, event_observed_color='#A60628', event_censored_color='#348ABD', ax=None, **kwargs)¶ Returns a lifetime plot, see examples: https://lifelines.readthedocs.io/en/latest/Survival%20Analysis%20intro.html#Censoring
Parameters:  durations ((n,) numpy array or pd.Series) – duration subject was observed for.
 event_observed ((n,) numpy array or pd.Series) – array of booleans: True if event observed, else False.
 entry ((n,) numpy array or pd.Series) – offsetting the births away from t=0. This could be from lefttruncation, or delayed entry into study.
 left_truncated (boolean) – if entry is provided, and the data is lefttruncated, this will display additional information in the plot to reflect this.
 sort_by_duration (boolean) – sort by the duration vector
 event_observed_color (str) – default: “#A60628”
 event_censored_color (str) – default: “#348ABD”
Returns: Return type: ax
Examples
>>> from lifelines.datasets import load_waltons >>> from lifelines.plotting import plot_lifetimes >>> T, E = load_waltons()["T"], load_waltons()["E"] >>> ax = plot_lifetimes(T.loc[:50], event_observed=E.loc[:50])

lifelines.plotting.
qq_plot
(model, ax=None, **plot_kwargs)¶ Produces a quantilequantile plot of the empirical CDF against the fitted parametric CDF. Large deviances away from the line y=x can invalidate a model (though we expect some natural deviance in the tails).
Parameters:  model (obj) – A fitted lifelines univariate parametric model, like
WeibullFitter
 plot_kwargs – kwargs for the plot.
Returns: The axes which was used.
Return type: ax
Examples
>>> from lifelines import * >>> from lifelines.plotting import qq_plot >>> from lifelines.datasets import load_rossi >>> df = load_rossi() >>> wf = WeibullFitter().fit(df['week'], df['arrest']) >>> qq_plot(wf)
 model (obj) – A fitted lifelines univariate parametric model, like

lifelines.plotting.
cdf_plot
(model, timeline=None, ax=None, **plot_kwargs)¶