Update range with the same number of samples, Makie

How to use the information from ax.finallimits[] to update my plot to a new range in x and y when I do zoom in or zoom out in my plot? The catch is that the number of samples needs to remain the same.

using GLMakie
fig = Figure(resolution =(600,400))
m = rand(10,10)
x = 1:10
y = 1:10
ax = Axis(fig[1,1])
heatmap!(ax, x, y, m)
lim = ax.finallimits[]
fig

so that when I zoom in, let’s say now my limits are from 2 to 4 in x and 3 to 6 in y but I still want 10 numbers in those intervals.

This works, although it updates twice per limit change because I was lazy.

fig = Figure(resolution =(600,400), font = "Arial")
ax = Axis(fig[1,1])

f(x, y) = sin(x) * cos(y)
xrange = lift(ax.finallimits) do lims
    range(minimum(lims)[1], maximum(lims)[1], length = 10)
end
yrange = lift(ax.finallimits) do lims
    range(minimum(lims)[2], maximum(lims)[2], length = 10)
end

heatmap!(ax, xrange, yrange, f)

fig
1 Like