Skip to content

Commit 5fee627

Browse files
committed
fix large extrapad when effects and ci were large
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.
1 parent 4009386 commit 5fee627

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

forestplot/graph_utils.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
warnings.filterwarnings("ignore")
1010

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

1215
def draw_ci(
1316
dataframe: pd.core.frame.DataFrame,
@@ -227,8 +230,7 @@ def draw_pval_right(
227230
if pd.isna(yticklabel2):
228231
yticklabel2 = ""
229232

230-
extrapad = 0.05
231-
pad = ax.get_xlim()[1] * (1 + extrapad)
233+
pad = _get_pad(ax, **kwargs)
232234
t = ax.text(
233235
x=pad,
234236
y=yticklabel1,
@@ -324,8 +326,7 @@ def draw_yticklabel2(
324326
yticklabel1 = row["yticklabel"]
325327
yticklabel2 = row["yticklabel2"]
326328

327-
extrapad = 0.05
328-
pad = ax.get_xlim()[1] * (1 + extrapad)
329+
pad = _get_pad(ax, **kwargs)
329330
if (ix == top_row_ix) and (
330331
annoteheaders is not None or right_annoteheaders is not None
331332
):
@@ -694,8 +695,7 @@ def draw_tablelines(
694695
[x0, x1], [nrows - 1.45, nrows - 1.45], color="0.5", linewidth=lower_lw, clip_on=False
695696
)
696697
if (right_annoteheaders is not None) or (pval is not None):
697-
extrapad = kwargs.get("extrapad", 0.05)
698-
x0 = ax.get_xlim()[1] * (1 + extrapad)
698+
x0 = _get_pad(ax, **kwargs)
699699
plt.plot(
700700
[x0, righttext_width],
701701
[nrows - 0.4, nrows - 0.4],

0 commit comments

Comments
 (0)