Skip to content

Commit d450c8c

Browse files
jayzhou2309claude
andcommitted
fix: honor aspect='auto' in px.imshow for RGB images
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>
1 parent 5d475c6 commit d450c8c

2 files changed

Lines changed: 4 additions & 0 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
77
### Fixed
88
- Fix concurrent first access to lazily initialized graph object properties, which could raise `ValueError("Invalid value")` [[#3441](https://github.com/plotly/plotly.py/issues/3441)], with thanks to @hb1915 for the contribution!
99
- Fix `px.sunburst`, `px.treemap` and `px.icicle` listing sectors in a different order on every run when `path` is used with a Polars DataFrame; sectors now follow their order of first appearance for all dataframe backends [[#5765](https://github.com/plotly/plotly.py/issues/5765)], with thanks to @Irahan2 for the contribution!
10+
- Fix `px.imshow` ignoring `aspect="auto"` for RGB and RGBA images, which kept their pixels square instead of stretching the image to fill the axes [[#5172](https://github.com/plotly/plotly.py/issues/5172)], with thanks to @jayzhou2309 for the contribution!
1011

1112

1213
## [7.1.0] - 2026-09-15

‎plotly/express/_imshow.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,9 @@ def imshow(
631631
if animation_frame:
632632
fig.frames = frame_list
633633
fig.update_layout(layout)
634+
if trace["type"] == "image" and aspect == "auto":
635+
# plotly.js anchors the y axis of an image trace to its x axis by default
636+
fig.update_yaxes(scaleanchor=False)
634637
# Hover name, z or color
635638
if binary_string and rescale_image and not np.all(img == img_rescaled):
636639
# we rescaled the image, hence z is not displayed in hover since it does

0 commit comments

Comments
 (0)