Skip to content

Commit

Permalink
fix large extrapad when effects and ci were large
Browse files Browse the repository at this point in the history
extrapad was calculated as xlim[1] * (1 + extrapad) which becomes extremely large when effects are not close to 0.
These lines were refactored into a function _get_pad() which
uses the range xlim[1] - xlim[0] as reference to compute the pad, which fixes the issue.
  • Loading branch information
EythorE committed Oct 10, 2023
1 parent 4009386 commit 5fee627
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions forestplot/graph_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

warnings.filterwarnings("ignore")

def _get_pad(ax: Axes, **kwargs) -> float:
extrapad = kwargs.get("extrapad", 0.05)
return ax.get_xlim()[1] + extrapad*(ax.get_xlim()[1] - ax.get_xlim()[0])

def draw_ci(
dataframe: pd.core.frame.DataFrame,
Expand Down Expand Up @@ -227,8 +230,7 @@ def draw_pval_right(
if pd.isna(yticklabel2):
yticklabel2 = ""

extrapad = 0.05
pad = ax.get_xlim()[1] * (1 + extrapad)
pad = _get_pad(ax, **kwargs)
t = ax.text(
x=pad,
y=yticklabel1,
Expand Down Expand Up @@ -324,8 +326,7 @@ def draw_yticklabel2(
yticklabel1 = row["yticklabel"]
yticklabel2 = row["yticklabel2"]

extrapad = 0.05
pad = ax.get_xlim()[1] * (1 + extrapad)
pad = _get_pad(ax, **kwargs)
if (ix == top_row_ix) and (
annoteheaders is not None or right_annoteheaders is not None
):
Expand Down Expand Up @@ -694,8 +695,7 @@ def draw_tablelines(
[x0, x1], [nrows - 1.45, nrows - 1.45], color="0.5", linewidth=lower_lw, clip_on=False
)
if (right_annoteheaders is not None) or (pval is not None):
extrapad = kwargs.get("extrapad", 0.05)
x0 = ax.get_xlim()[1] * (1 + extrapad)
x0 = _get_pad(ax, **kwargs)
plt.plot(
[x0, righttext_width],
[nrows - 0.4, nrows - 0.4],
Expand Down

0 comments on commit 5fee627

Please sign in to comment.