# Plots.jl: shared colorbar with subplots?

**URL:** <https://discourse.julialang.org/t/plots-jl-shared-colorbar-with-subplots/47269>\
**Category:** General Usage\
**Tags:** plotting\
**Created:** [September 25, 2020, 3:05pm UTC](https://discourse.julialang.org/t/plots-jl-shared-colorbar-with-subplots/47269 "2020-09-25T15:05:18Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![DanielIngraham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielingraham/32/13055_2.png) [@DanielIngraham](https://discourse.julialang.org/u/DanielIngraham)\
**Post date:** [September 25, 2020, 7:20pm UTC](https://discourse.julialang.org/t/plots-jl-shared-colorbar-with-subplots/47269/5 "2020-09-25T19:20:11Z")

</div>

Great, that seemed to do it. Here’s what I ended up with:

```julia
using Plots
function doit2()
    x1 = range(0.0, 1.0, length=51)
    y1 = range(-1.0, 0.0, length=51)
    z1 = sin.(4*pi.*x1)*cos.(6*pi.*reshape(y1, 1, :))

    x2 = range(0.25, 1.25, length=51)
    y2 = range(-1.0, 0.0, length=51)
    z2 = 2.0.*sin.(4*pi.*x2)*cos.(6*pi.*reshape(y2, 1, :))

    x3 = range(0.0, 1.0, length=51)
    y3 = range(-1.25, -0.25, length=51)
    z3 = 3.0*sin.(4*pi.*x3)*cos.(6*pi.*reshape(y3, 1, :))

    x4 = range(0.25, 1.25, length=51)
    y4 = range(-1.25, -0.25, length=51)
    z4 = 4.0.*sin.(4*pi.*x4)*cos.(6*pi.*reshape(y4, 1, :))

    clims = extrema([z1; z2; z3; z4])
    p1 = contourf(x1, y1, z1, clims=clims, c=:viridis, colorbar=false)
    p2 = contourf(x2, y2, z2, clims=clims, c=:viridis, colorbar=false)
    p3 = contourf(x3, y3, z3, clims=clims, c=:viridis, colorbar=false)
    p4 = contourf(x4, y4, z4, clims=clims, c=:viridis, colorbar=false)

    h2 = scatter([0,0], [0,1], zcolor=[0,3], clims=clims,
                 xlims=(1,1.1), label="", c=:viridis, colorbar_title="cbar", framestyle=:none)

    l = @layout [grid(2, 2) a{0.035w}]
    p_all = plot(p1, p2, p3, p4, h2, layout=l, link=:all)
    savefig(p_all, "shared_colorbar_julia2.png")
end

```

The plot:  
 ![shared_colorbar_julia2](https://global.discourse-cdn.com/julialang/original/3X/5/4/54cc38596d5eb785917988c246c9bf9ad36c81a0.png)

Thanks everyone!

---

_[View the full topic](https://discourse.julialang.org/t/plots-jl-shared-colorbar-with-subplots/47269)._
