Repository navigation
[FEATURE]: autorangePadding #5555
Description
Activity
Thanks for the idea! At this time, we're not planning on implementing a
autorangePaddingattribute, but exposing more information is something we're open to. That work would be covered in #5552. Let's keep the discussion about accessing additional information in that issue.Thanks for the clarification — that makes sense, and I appreciate the transparency about
the current roadmap.I understand the preference to keep
autorangePaddingas a separate concern, and I am fully
on board with focusing the "expose more computed information" discussion in #5552.To make sure my thoughts are useful there, I'll summarize what I'd want to contribute to
that issue specifically around autorange:What I'd add to #5552 regarding autorange introspection:
-
The core ask — computed axis ranges — being able to retrieve the final rendered
[min, max]for each axis in a production-safe, lightweight way. I know this is already
part of the discussion there, but I wanted to flag it as the highest-priority item from
my side. -
The padding breakdown — even without a settable
autorangePaddingattribute, it
would still be very useful to know how much of the rendered range is data vs. padding.
For example:
computed = fig.get_computed_values(include=["axis_ranges", "autorange_padding"]) # "autorange_padding": { # "xaxis": {"before": 0.05, "after": 0.05} # }
This is read-only introspection only — no new attribute, no write-side change — which
hopefully fits within the scope of what #5552 is trying to do.- Multi-figure alignment use case — the most common reason users need this information
is to align axis ranges across two figures that share a conceptual axis (e.g. a price
chart above a volume chart). If [FEATURE]: Access values calculated / derived by plotly.js as part of plotting #5552 exposes the final rendered range, that use case is
already largely solved. I'll note this explicitly in that issue so the motivation is clear.
I will go ahead and add a focused comment in #5552 with these points. Thanks again for
redirecting rather than just closing — it's clear there's genuine interest in making
computed values accessible and I'm glad to contribute to that discussion.-
Can you assign to me. Would love to work on this.
[FEATURE]:
autorangePadding— Explicit Control and Introspection of Autorange PaddingSummary
When
autorange: trueis set on an axis, Plotly silently adds a padding fractionaround the data range. This padding is internally computed, never documented as a
configurable value, and impossible to query without using
full_figure_for_development().This issue proposes:
autorangePaddingto give users explicit controlover the padding fraction
get_computed_values()for introspectionProblem Statement
Autorange padding causes subtle but persistent issues in several common workflows:
Problem 1 — Multi-figure axis alignment:
Two figures sharing a conceptual x-axis (e.g. a price chart above a volume chart)
will not align perfectly even when their data ranges are identical, because autorange
applies padding independently on each figure. There is no way to force consistent
padding without disabling autorange entirely.
Problem 2 — Controlled range extension:
A user wants autorange but needs extra space on one side for an annotation or legend.
Currently this is impossible without computing the full data range manually and setting
a fixed range — defeating the purpose of autorange.
Problem 3 — Range introspection in production:
Users who need the exact rendered axis range must use
full_figure_for_development(),which is explicitly documented as not for production use. There is no lightweight
alternative.
Proposed Solution
1. New Layout Attribute:
autorangePaddingSet per axis as a fraction of the total data range:
Default value matches the current implicit behavior so all existing figures are
unaffected.
Asymmetric Padding
For cases where padding is only needed on one side:
before= lower end of the axis,after= upper end, regardless of axis direction.2. Introspection via
get_computed_values()Returns:
{ "axis_ranges": { "xaxis": [-0.5, 10.5], "yaxis": [-4.35, 102.1] }, "autorange_padding": { "xaxis": { "before": 0.05, "after": 0.05, "pixels": {"before": 18.4, "after": 18.4} }, "yaxis": { "before": 0.05, "after": 0.05, "pixels": {"before": 14.2, "after": 14.2} } } }Both fractional and pixel values are returned, making the result useful for
data-space alignment and pixel-space layout work respectively.
3. Companion Utility:
match_axis_ranges()(Optional)A natural extension that syncs axis ranges across multiple figures:
Computes the union of both figures' data ranges and applies a consistent range to both
so they align exactly — the most common use case motivating this feature.
Relationship to
get_computed_values()This feature is a direct extension of the
get_computed_values()proposal:axis_rangesalready proposes returning the final rendered rangeautorange_paddingextends that with a breakdown of how much of the range ispadding vs. actual data span
autorangePaddingis the write-side complement to the read-side introspectionTogether they give full round-trip control: set the padding you want, then verify
exactly what was applied.
Prior Art
matplotlibax.margins(x=0.05)sets padding;ax.get_xlim()returns final rangeVega-Lite"padding"property on scale definitionsD3.jsscale.nice()and directscale.domain()controlBackward Compatibility
autorangePaddingis a new optional attribute. Omitting it preserves current behavior exactly.Acceptance Criteria
autorangePaddingaccepted as a per-axis layout attribute (scalar or asymmetric dict)get_computed_values(include=["autorange_padding"])match_axis_ranges()utility considered as a follow-up or included in scopeRelated Issues
[FEATURE]: get_computed_values()([FEATURE]: Access values calculated / derived by plotly.js as part of plotting #5552)[FEATURE]: get_subplot_geometry()([FEATURE]: get_subplot_geometry() #5554)