Skip to content

Commit

Permalink
added title and show args
Browse files Browse the repository at this point in the history
  • Loading branch information
aGuyLearning committed Dec 13, 2024
1 parent 613be89 commit 8c3d170
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions ehrapy/plot/_survival_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@ def cox_ph_forestplot(
decimal: int = 2,
text_size: int = 12,
color: str = "k",
show: bool = True,
title: str | None = None,
):
"""Generates a forest plot to visualize the coefficients and confidence intervals of a Cox Proportional Hazards model.
The method requires a fitted CoxPHFitter object from the lifelines library.
Expand All @@ -330,6 +332,8 @@ def cox_ph_forestplot(
decimal: Number of decimal places to display.
text_size: Font size of the text.
color: Color of the markers.
show: Show the plot, do not return axis.
title: Set the title of the plot.
Examples:
>>> import ehrapy as ep
Expand Down Expand Up @@ -389,7 +393,7 @@ def cox_ph_forestplot(

x_axis_lower_bound = round(((pd.to_numeric(coxph_summary["coef lower 95%"])).min() - 0.1), 1)

fig = plt.figure(figsize=fig_size)
plt.figure(figsize=fig_size)
gspec = gridspec.GridSpec(1, 6)
plot = plt.subplot(gspec[0, 0:4]) # plot of data
tabl = plt.subplot(gspec[0, 4:]) # table
Expand Down Expand Up @@ -434,4 +438,12 @@ def cox_ph_forestplot(
plot.spines["top"].set_visible(False)
plot.spines["right"].set_visible(False)
plot.spines["left"].set_visible(False)
return fig, plot

if title:
plt.title(title)

if not show:
return plot

else:
return None

0 comments on commit 8c3d170

Please sign in to comment.