Skip to content

Log axis with explicit margin= can underflow its padded lower bound to 0 #350

Description

@masenf

In the explicit-margin log branch of the axis range computation (python/xy/_figure.py, out_lo = 10.0 ** (transformed_lo - pad) — lines ~1126–1130 at 9fdc236), the padded lower bound can underflow to 0.0: with e.g. data spanning lo=1e-300 to hi=1e10 and margin=0.1, transformed_lo - pad ≈ -331 and 10.0**-331 == 0.0, leaving a log axis with a non-positive lower bound.

The default-margin path already guards against this with a positive floor:

if scale == "log" and configured_margin is None:
    out_lo = max(out_lo, lo / 10.0, np.nextafter(0.0, 1.0))

Fix sketch: apply the np.nextafter(0.0, 1.0) floor in the explicit-margin branch as well (only the floor — the lo / 10.0 clamp would defeat an authored margin), plus a regression test with a pathological-but-legal domain.

Provenance: pre-existing on main; surfaced by CodeRabbit while reviewing the merge commit in #347, where it is outside the diff and out of scope (that PR is a notebook display change).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions