Skip to content

Fix px.imshow ignoring aspect='auto' for RGB images - #5788

Open
jayzhou2309 wants to merge 2 commits into
plotly:mainfrom
jayzhou2309:fix/imshow-rgb-aspect-auto
Open

jayzhou2309 wants to merge 2 commits into
plotly:mainfrom
jayzhou2309:fix/imshow-rgb-aspect-auto

Conversation

@jayzhou2309

Copy link
Copy Markdown

Link to issue

Closes #5172

Description of change

plotly.js anchors the y axis of an image trace to its x axis by default, so pixels render square (the layout.yaxis.scaleanchor reference describes this default, and scaleanchor: false turns it off). px.imshow sets axis constraints only for aspect="equal", so for RGB and RGBA images, which use go.Image, aspect="auto" changed nothing and the image kept its original aspect ratio.

This PR sets scaleanchor=False on every y axis when px.imshow builds an image trace with aspect="auto". fig.update_yaxes covers 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 aspect argument. 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=400 and no margins:

  • main (d586d22), aspect="auto": the image spans 400x400 px
  • this PR, aspect="auto": the image spans 800x400 px
  • this PR, aspect="equal": the image spans 400x400 px, unchanged

Testing strategy

  • test_image_trace_aspect builds a two-facet RGB figure, with and without binary_string. With aspect="auto" every y axis has scaleanchor == False. With the default aspect every y axis keeps scaleanchor unset. It fails on main (2 failed) and passes here.
  • tests/test_optional/test_px: 1227 passed, 10 skipped, 4 xfailed.
  • ruff format --check and ruff check pass 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.

jayzhou2309 and others added 2 commits October 2, 2026 11:56
…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

No deployments
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.

aspect="auto" for px.imshow does nothing when plotting RGB data

1 participant