Skip to content

Fix partial autorange when range contains None elements#5543

Closed
Krishnachaitanyakc wants to merge 3 commits intoplotly:mainfrom
Krishnachaitanyakc:fix-partial-autorange-5536
Closed

Fix partial autorange when range contains None elements#5543
Krishnachaitanyakc wants to merge 3 commits intoplotly:mainfrom
Krishnachaitanyakc:fix-partial-autorange-5536

Conversation

@Krishnachaitanyakc
Copy link

Summary

Fixes #5536

When setting range=[value, None] or range=[None, value] on an axis (e.g., fig.update_yaxes(range=[0, None])), plotly.js should use partial autoranging to fix one bound while autoranging the other. However, the plotly.js impliedEdits mechanism automatically sets autorange=false whenever range is specified, which prevents partial autoranging from working.

This PR fixes the issue by explicitly setting the autorange property to the appropriate value when range contains None elements:

  • range=[value, None] sets autorange="max" (fix lower bound, autorange upper)
  • range=[None, value] sets autorange="min" (autorange lower, fix upper bound)
  • range=[None, None] sets autorange=True (autorange both)
  • range=[value, value] does not set autorange (no change, existing behavior)

The fix is implemented in two places in plotly/basedatatypes.py:

  1. _perform_update -- handles update_yaxes(), update_xaxes(), update_layout(), and other update methods. When autorange is explicitly provided by the user in the same update call, the explicit value takes precedence.
  2. __setitem__ -- handles direct property assignment like fig.layout.yaxis.range = [0, None].

Test plan

  • Added 9 unit tests in tests/test_core/test_update_objects/test_update_subplots.py covering:
    • Upper bound None sets autorange="max"
    • Lower bound None sets autorange="min"
    • Both bounds None sets autorange=True
    • No None does not set autorange
    • Works on both xaxis and yaxis
    • Explicit autorange in same update call takes precedence
    • Dict ordering does not affect explicit autorange precedence
    • Direct property assignment works
    • update_layout(yaxis_range=...) works
  • All existing tests pass (1735 passed, 1 pre-existing failure unrelated to this change)

When setting `range=[value, None]` or `range=[None, value]` on an axis,
plotly.js should use partial autoranging (autorange="max" or "min").
However, plotly.js impliedEdits mechanism sets autorange=false whenever
range is specified, which prevents partial autoranging from working.

This fix explicitly sets the autorange property to the appropriate value
when range contains None elements:
- range=[value, None] -> autorange="max"
- range=[None, value] -> autorange="min"
- range=[None, None] -> autorange=True

The fix handles all code paths: update_yaxes/update_xaxes, update_layout,
and direct property assignment. When the user explicitly provides an
autorange value in the same update call, it takes precedence.

Fixes plotly#5536
Apply ruff format to fix code style issues flagged by CI:
- Collapse multi-line if conditions onto single lines where they fit
- Fix lambda expression formatting in layout_keys_filters
@camdecoster
Copy link
Contributor

Thanks for the PR. One of our team members will review and follow up.

The test_optional_py-3.13 CI job failed due to a BrowserDepsError in
test_kaleido (missing Chromium system dependencies), not due to any
code change in this PR. Retriggering CI with empty commit.
@emilykl
Copy link
Contributor

emilykl commented Mar 25, 2026

Hi @Krishnachaitanyakc, thanks for the contribution.

I'm not totally sure this addresses the root issue, since I can see that in plotly.py 6.6.0, autorange is already correctly set to "max" in plotly.js when only a lower bound is provided in plotly.py:

Screenshot 2026-03-25 at 4 14 31 PM

That said, it's at least plausible that we might want to do special handling of autorange in plotly.py.

Could you update your PR description to match the template and include screenshots/videos of the fix in action?

Take a look at my comment here as well which has a tiny bit more info.

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]: Setting only an upper or lower bound for axes does not work in Jupyter

3 participants