Fix partial autorange when range contains None elements#5543
Closed
Krishnachaitanyakc wants to merge 3 commits intoplotly:mainfrom
Closed
Fix partial autorange when range contains None elements#5543Krishnachaitanyakc wants to merge 3 commits intoplotly:mainfrom
Krishnachaitanyakc wants to merge 3 commits intoplotly:mainfrom
Conversation
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
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.
Contributor
|
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,
That said, it's at least plausible that we might want to do special handling of 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Fixes #5536
When setting
range=[value, None]orrange=[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.jsimpliedEditsmechanism automatically setsautorange=falsewheneverrangeis specified, which prevents partial autoranging from working.This PR fixes the issue by explicitly setting the
autorangeproperty to the appropriate value whenrangecontainsNoneelements:range=[value, None]setsautorange="max"(fix lower bound, autorange upper)range=[None, value]setsautorange="min"(autorange lower, fix upper bound)range=[None, None]setsautorange=True(autorange both)range=[value, value]does not setautorange(no change, existing behavior)The fix is implemented in two places in
plotly/basedatatypes.py:_perform_update-- handlesupdate_yaxes(),update_xaxes(),update_layout(), and other update methods. Whenautorangeis explicitly provided by the user in the same update call, the explicit value takes precedence.__setitem__-- handles direct property assignment likefig.layout.yaxis.range = [0, None].Test plan
tests/test_core/test_update_objects/test_update_subplots.pycovering:Nonesetsautorange="max"Nonesetsautorange="min"Nonesetsautorange=TrueNonedoes not setautorangeautorangein same update call takes precedenceautorangeprecedenceupdate_layout(yaxis_range=...)works