Fix px.imshow ignoring aspect='auto' for RGB images - #5788
Open
jayzhou2309 wants to merge 2 commits into
Open
jayzhou2309 wants to merge 2 commits into
jayzhou2309 wants to merge 2 commits into
Conversation
…ault Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
plotly.js anchors the y axis of an image trace to its x axis by default, so px.imshow kept square pixels for RGB and RGBA images even with aspect='auto'. Set scaleanchor=False on every y axis in that case. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Link to issue
Closes #5172
Description of change
plotly.js anchors the y axis of an
imagetrace to its x axis by default, so pixels render square (thelayout.yaxis.scaleanchorreference describes this default, andscaleanchor: falseturns it off).px.imshowsets axis constraints only foraspect="equal", so for RGB and RGBA images, which usego.Image,aspect="auto"changed nothing and the image kept its original aspect ratio.This PR sets
scaleanchor=Falseon every y axis whenpx.imshowbuilds animagetrace withaspect="auto".fig.update_yaxescovers each facet's y axis, not only the first one. Heatmap traces get no default anchor, so the 2D path is unchanged.aspect="equal", and the numpy default, still render square pixels.This also changes xarray RGB images with no
aspectargument. Their documented default is"auto", so they now stretch to fill the axes like xarray 2D images already do.Demo
A 100x100 red RGB image rendered with kaleido at
width=800, height=400and no margins:aspect="auto": the image spans 400x400 pxaspect="auto": the image spans 800x400 pxaspect="equal": the image spans 400x400 px, unchangedTesting strategy
test_image_trace_aspectbuilds a two-facet RGB figure, with and withoutbinary_string. Withaspect="auto"every y axis hasscaleanchor == False. With the default aspect every y axis keepsscaleanchorunset. It fails on main (2 failed) and passes here.tests/test_optional/test_px: 1227 passed, 10 skipped, 4 xfailed.ruff format --checkandruff checkpass on the changed files.AI disclosure
An AI agent (Claude Code) reproduced the issue with a kaleido render, wrote the failing test and the fix, and ran the commands above.
Guidelines
🤖 Written and posted by an AI agent (Claude Code) on behalf of @jayzhou2309.