Skip to content

Commit aa298cd

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 3fbc0c7 commit aa298cd

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
@@ -8,6 +8,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
88
- Fix concurrent first access to lazily initialized graph object properties, which could raise `ValueError("Invalid value")` [[#5691](https://github.com/plotly/plotly.py/pull/5691)], with thanks to @hb1915 for the contribution!
99
- Fix `mpl_to_plotly` crashing on touching bars (such as `plt.hist`) due to floating-point noise producing negative `bargap` values by clamping `bargap` to `[0, 1]` [[#5696](https://github.com/plotly/plotly.py/pull/5696)], with thanks to @robertoffmoura for the contribution!
1010
- 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 [[#5766](https://github.com/plotly/plotly.py/pull/5766)], with thanks to @Irahan2 for the contribution!
11+
- 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 [[#5788](https://github.com/plotly/plotly.py/pull/5788)], with thanks to @jayzhou2309 for the contribution!
1112

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

‎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)