[FEATURE]: autorangePadding
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 18.8k
- Fork
- 2.8k
- Merge trung bình
- 16 giờ 26 phút
- Pull request đã merge (30 ngày)
- 21
Mô tả
[FEATURE]: autorangePadding — Explicit Control and Introspection of Autorange Padding
Summary
When autorange: true is set on an axis, Plotly silently adds a padding fraction
around 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:
- A new per-axis layout attribute
autorangePaddingto give users explicit control
over the padding fraction - Exposure of the computed padding via
get_computed_values()for introspection
Problem 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: autorangePadding
Set per axis as a fraction of the total data range:
fig.update_layout(
xaxis=dict(
autorange=True,
autorangePadding=0.05 # 5% padding each side — matches current default behavior
),
yaxis=dict(
autorange=True,
autorangePadding=0.0 # no padding — data fills axis edge to edge
)
)
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:
fig.update_layout(
yaxis=dict(
autorange=True,
autorangePadding=dict(before=0.0, after=0.15) # extra headroom at top only
)
)
before = lower end of the axis, after = upper end, regardless of axis direction.
2. Introspection via get_computed_values()
computed = fig.get_computed_values(include=["axis_ranges", "autorange_padding"])
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:
import plotly.utils as pu
pu.match_axis_ranges([fig1, fig2], axis="x")
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 is
padding vs. actual data spanautorangePaddingis the write-side complement to the read-side introspection
Together they give full round-trip control: set the padding you want, then verify
exactly what was applied.
Prior Art
| Tool | Equivalent |
|---|---|
matplotlib |
ax.margins(x=0.05) sets padding; ax.get_xlim() returns final range |
Vega-Lite |
Explicit "padding" property on scale definitions |
D3.js |
scale.nice() and direct scale.domain() control |
Backward Compatibility
autorangePaddingis a new optional attribute. Omitting it preserves current behavior exactly.- No existing figures, layouts, or workflows are affected unless users explicitly opt in.
Acceptance Criteria
-
autorangePaddingaccepted as a per-axis layout attribute (scalar or asymmetric dict) - Default value matches current implicit padding so existing figures are unchanged
- Computed padding values returned via
get_computed_values(include=["autorange_padding"]) - Both fractional and pixel padding values included in the return
- Documented in the axis layout attribute reference
-
match_axis_ranges()utility considered as a follow-up or included in scope
Related Issues
- Companion to:
[FEATURE]: get_computed_values()(https://github.com/plotly/plotly.py/issues/5552) - Companion to:
[FEATURE]: get_subplot_geometry()(https://github.com/plotly/plotly.py/issues/5554) - Related to any issue requesting consistent axis ranges across multiple figures
I am happy to discuss the naming convention for
autorangePaddingvsautorange_padding
to match the existing attribute style guide, and whether thematch_axis_ranges()
utility belongs in this issue or a separate one.
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng việc xem xét đề xuất get_computed_values() liên quan trong issue 5552 và tài liệu tham chiếu hiện có về các thuộc tính bố cục trục. Xác định phạm vi giữa autorangePadding, việc introspection các giá trị đã tính toán và tiện ích tùy chọn match_axis_ranges(). Công việc được xem là hoàn tất khi các tiêu chí chấp nhận đã thống nhất được triển khai, kiểm thử và ghi tài liệu mà không thay đổi hành vi mặc định hiện có.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- data-visualization
- Loại issue
- Tính năng
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức độ hoạt động
- Ít trao đổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100