06 · Automatic axis range
Large positive and negative effects exercise automatic limits, automatic ticks, a reference line, and an ideal-value line.
Run the example
from forestploter import read_forest_data
from forestploter.gallery_cases import plot_auto_scale_mixed_effects
df = read_forest_data("06_auto_scale_mixed_effects.xlsx", sheet_name="Forest")
result = plot_auto_scale_mixed_effects(df)
result.save("06_auto_scale_mixed_effects.png", dpi=300)
Plot function used by the gallery and tests
def plot_auto_scale_mixed_effects(df: ForestInput) -> ForestPlotResult:
"""Plot case 06: automatic limits for heterogeneous effects."""
columns = (
ForestColumn("outcome", "Outcome", "text", 2.5),
ForestColumn("scale", "Measurement scale", "text", 1.3),
ForestColumn("n", "N", "numeric", 0.6, "right"),
ForestColumn("effect_display", "Standardized effect [95% CI]", "numeric", 2.0, "right"),
ForestColumn("ci", "Automatically derived axis", "ci", 3.4, "center"),
)
return forest(
df,
columns=columns,
ref_line=0.0,
ideal_line=-0.5,
xlim=None,
ticks_at=None,
arrow_lab=("Lower standardized effect", "Higher standardized effect"),
title="Automatic axis range across heterogeneous effect magnitudes",
figure_width=12.5,
reference_legend=ForestReferenceLegendSpec(
reference_label="No difference",
ideal_label="Target effect",
location="bottom",
ncol=2,
),
)