Skip to content

Keep autorange on matching axes when another match group sets a range - #8165

Open
X6M-Work wants to merge 3 commits into
plotly:mainfrom
X6M-Work:fix-shared-axes-autorange-8053
Open

X6M-Work wants to merge 3 commits into
plotly:mainfrom
X6M-Work:fix-shared-axes-autorange-8053

Conversation

@X6M-Work

@X6M-Work X6M-Work commented Nov 8, 2026

Copy link
Copy Markdown

Fixes #8053.

Problem

With make_subplots(rows=2, cols=2, shared_xaxes=True, shared_yaxes=True) and a range set on the x axes, the y axes stop autoranging and show [-1, 4]. The layout from the issue boils down to four match groups, {x, x3} and {x2, x4} with a range, then {y, y2} and {y3, y4} without one:

xaxis:  {range: [0, 100], matches: 'x3'},  yaxis:  {},
xaxis2: {range: [0, 100], matches: 'x4'},  yaxis2: {matches: 'y'},
xaxis3: {range: [0, 100]},                 yaxis3: {},
xaxis4: {range: [0, 100]},                 yaxis4: {matches: 'y3'}

Cause

In constraints.handleDefaults, hasRange is declared once, before the loop over match groups, and never reset. After the first x group sets it, every later group with no explicit autorange gets autorange: false. The y axes then have no range and fall back to the default one. It needs at least two match groups, which is why the issue only shows up with more than one row and more than one column.

Resetting hasRange for each group exposed a second problem, caught by the existing should match set axis range value for matching axes test. The explicit-range check ran after the loop and read axIn, which is the last axis visited, not the axis the range came from. For the {x3, y3} group in that test, the range comes from yaxis3, but the loop ends on xaxis3, which has none. The test only passed because hasRange leaked in from the {y, y2} group processed before it.

Changes

  • Reset hasRange at the start of each match group.
  • Set hasRange in setAttrVal, from the input of the axis that supplies the range, with the same validity check as before.

Tests

New axes_test.js case using the layout above: the x axes keep autorange: false and the y axes get autorange: true. It fails on main (Expected false to be true, 'yaxis', same for yaxis2-yaxis4).

Locally (Windows 11, Chrome 156):

  • axes_test.js: 407 passed, 2 failed. The 2 failures (insiderange relayout, insiderange react to new data) also fail on main here, off by a few pixels.
  • cartesian_test.js, cartesian_interact_test.js, splom_test.js, range_slider_test.js, plot_api_react_test.js: the same 12 drag, map and WebGL tests fail with and without this change, and the rest pass.
  • biome lint passes on the changed files.

I didn't run the image baseline tests.

`hasRange` was never reset between match groups, so once a group with an
explicit range was processed, every later group without `autorange` got
`autorange: false` and fell back to the default range. With shared x and
y axes on a grid and a range set on the x axes, the y axes stopped
autoranging.

The explicit-range check also read `axIn` after the loop, which is the
last axis visited rather than the axis the range came from. Check it
where the value is picked instead.

Fixes plotly#8053
@KoolADE85 KoolADE85 self-assigned this Nov 9, 2026
@KoolADE85
KoolADE85 self-requested a review November 9, 2026 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: Y-axis autorange stops working when updating the xaxes range for subplots with shared x-axes and y-axes

2 participants