plotly.py icon indicating copy to clipboard operation
plotly.py copied to clipboard

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

Open martinsondergaard opened this issue 8 months ago • 1 comments

I am trying to plot an RGB image that strecthes to fill the figure, and I cannot get it to work.

Using a standard 2D array works as expected, and the image is able to dynamically stretch to the figure.

arr = np.random.random((100, 100))
px.imshow(arr, aspect="auto")

But if I instead try to plot an RGB image with the same settings, then the image stays with its original aspect ratio.

img = np.random.random((100, 100, 3))
px.imshow(img, aspect="auto")

In this case, setting the aspect key does nothing and the image keeps a fixed aspect ratio. Explicitly adding with and height also does nothing to change the aspect ratio.

Is this an expected limitation of the aspect setting? If yes, then it should probably be documented.

martinsondergaard avatar May 09 '25 10:05 martinsondergaard

Any update on this? I'm running into the same issue. Trying to override it with any layout update to the figure such as scaleanchor=None or height/width setting doesn't work. There also doesn't seem to be a way to make auto aspect non-square pixels RGB image with go.Image, right? And no way to pass direct RGB data to a Heatmap, which allows those.

5xx7xx avatar Sep 27 '25 22:09 5xx7xx