Heatmap with irregularly spaced grids

One way of achieving this using Plots.jl is shown here and adapted below.

# 1 - INPUT DATA: generate non-linear grid and z variables
n = 20
x = zeros(n)
for i in 2:n
    x[i] = x[i-1] + (1 - x[i-1]) / (n-i+1)^1.25
end
r = @. x^2 + x'^2
z = @. sin(10*r) / (1 + r)
z2 =  0.5z

# 2 - PLOT DATA: multiple heatmaps with single colorbar
using Plots; gr()
clims = extrema([z; z2])
p1 = heatmap(x, x, z, ratio=1, clims=clims, cb=false, lims=extrema(x), tick_dir=:out)
p2 = heatmap(x, x, z2, ratio=1, clims=clims, cb=false, lims=extrema(x), tick_dir=:out)
p3 = scatter([0], [0], clims=clims, zcolor=clims, grid=false,
    xlims=(1,1.1), framestyle=:none, label="", cb_title="legend")
l = @layout[grid(1,2) a{0.05w}]
plot(p1, p2, p3, layout=l, size=(1000,400))

4 Likes