Heatmap problem with aspect ratio

I want plotly.graph_objects.Heatmap to display data as squares. I set height and width but it doesn’t work when the number of columns is much higher than rows

Here example where it works well:


(rows 39, cols 32 => height 574, width 700)

Here squares start showing as rectangles:
image
(rows 18, cols 34 => height 370, width 700)

And here they’re closer to showing as lines than squares:
image
(rows 15, cols 42 => height 250, width 700)

I set height and width using:

layout = dict(
                yaxis=...,
                xaxis=...,
                width=plot_width,
                height=plot_height,
                autosize=False
                )

fig = go.Figure(data=data, layout=layout)

What am I doing wrong?

Hello,
I’m not an expert on Heatmap but did you try this option ?
fig.update_scenes(aspectmode='data')

Thank you for your reply but unfortunately, it doesn’t seem to be making any difference. I tried all other aspectmode options and none makes data to be displayed as squares

For cartesian 2D plots use the following:

fig.update_layout(yaxis_scaleanchor="x")

or directly in the layout definition

yaxis_scaleanchor="x"

Exactly what I needed! thank you