Using same x- and y-axis scales in Makie plots

What is the simplest way to use the same scales in the x- and y-axis of the plots generated by Makie? For example, when visualizing a 5×3 array with heatmap() as

using GLMakie

I want the individual array entries to be shown as the same squares rather than elongated rectangles, such that the ratio between the x- and y-axis lengths is 5:3 on the screen for the above example.

I tried things like heatmap(rand(3,3), aspect=1) but it didn’t work. This section in the documentation seems relevant, but the examples there are a bit convoluted; I failed to create a working example that is suffciently short.

1 Like

I’ve figured it out. The following code seems working:

f = Figure()
ax = Axis(f, aspect=DataAspect())
heatmap!(ax, rand(5,3))

The key thing is to use heatmap!() rather than heatmap() in order to draw on the axis that is correctly set up.

1 Like

You can also do heatmap(args..., axis = (aspect = DataAspect(),)) to do it in one go

The syntax is explained here in more detail Plot Method Signatures · Makie Plotting Ecosystem

1 Like