# Heatmap with irregularly spaced grids

**URL:** <https://discourse.julialang.org/t/heatmap-with-irregularly-spaced-grids/77259>\
**Category:** Visualization\
**Tags:** plots\
**Created:** [March 1, 2022, 9:17pm UTC](https://discourse.julialang.org/t/heatmap-with-irregularly-spaced-grids/77259 "2022-03-01T21:17:50Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [March 1, 2022, 10:55pm UTC](https://discourse.julialang.org/t/heatmap-with-irregularly-spaced-grids/77259/7 "2022-03-01T22:55:31Z")

</div>

> [@fredrikpaues](#):
>
> ```julia
> But in Julia I can't figure out what to do...
> using Plots
> 
> ```

One way of achieving this using Plots.jl is [shown here](https://discourse.julialang.org/t/plots-jl-shared-colorbar-with-subplots/47269/5) and adapted below.

```julia
# 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))

```

 ![Plots_gr_heatmaps_single_colorbar](https://global.discourse-cdn.com/julialang/original/3X/5/0/50c988981485276557bad4949a7c700ee76357a9.png)

---

_[View the full topic](https://discourse.julialang.org/t/heatmap-with-irregularly-spaced-grids/77259)._
