# Makie: Colorbar with the "High" and "Low" labels

**URL:** https://discourse.julialang.org/t/makie-colorbar-with-the-high-and-low-labels/101604
**Category:** Visualization
**Tags:** makie, colorbar
**Created:** [July 14, 2023, 5:23am UTC](https://discourse.julialang.org/t/makie-colorbar-with-the-high-and-low-labels/101604 "2023-07-14T05:23:24Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![nari](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nari/32/46452_2.png) [@nari](https://discourse.julialang.org/u/nari)
#### Post date: [July 14, 2023, 5:23am UTC](https://discourse.julialang.org/t/makie-colorbar-with-the-high-and-low-labels/101604/1 "2023-07-14T05:23:24Z")

</div>

When accompanying a heatmap with a color bar, the values at both ends themselves have no physical meaning, only the type and which direction they are used in are sometimes important. In that case, I would prepare a color bar like the following.

Currently, the size of the color bar, the coordinates to place the label and the font size are entered manually. Any comments on documentation or code I should read in order to specify some of these parameters and have the rest automatically optimized for position and size would be appreciated.

```julia
using CairoMakie
begin
    fig = Figure()
    ax = CairoMakie.Axis(fig[1,1], height=300, width=300)
    heatmap!(0:0.1:10π, 0:0.1:10π, [cos(x)+sin(y) for x in 0:0.2:20π, y in 0:0.2:20π],colormap=:viridis)
    ax1 = CairoMakie.Axis(fig[1,2], limits=(0,1,0,1),height=180, width=40)
    hidedecorations!(ax1)
    hidespines!(ax1)
    Colorbar(fig[1,2], colormap=:viridis, colorrange=(0,1),vertical = true, height=120, width=15, halign=:center, valign=:center,flipaxis = true, labelsize=20, labelpadding=10, ticksvisible=false, ticklabelsvisible=false)
    text!(ax1, 0.5,1.0, text="High", fontsize=20, align=(:center,:top))
    text!(ax1, 0.5,0.0, text="Low", fontsize=20, align=(:center,:bottom))
    resize_to_layout!(fig)
    display(fig)
end

```

![colrbar](https://global.discourse-cdn.com/julialang/original/3X/1/2/12c9ac27d18b72db9630c8f90da89a41dcb3df07.png)

---

<div class="post-metadata">

### Author: ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)
#### Post date: [July 14, 2023, 9:40am UTC](https://discourse.julialang.org/t/makie-colorbar-with-the-high-and-low-labels/101604/2 "2023-07-14T09:40:10Z")

</div>

A slightly easier way is to use a subgrid and place two labels and the colorbar in there.

```julia
begin
    fig = Figure()
    ax = Axis(fig[1,1], height=300, width=300)
    heatmap!(0:0.1:10π, 0:0.1:10π, [cos(x)+sin(y) for x in 0:0.2:20π, y in 0:0.2:20π],colormap=:viridis)
    subgrid = GridLayout(fig[1, 2], tellheight = false)
    Label(subgrid[1, 1], "High")
    Colorbar(subgrid[2, 1], colormap=:viridis, colorrange=(0,1),vertical = true, height=120, width=15, halign=:center, valign=:center,flipaxis = true, labelsize=20, labelpadding=10, ticksvisible=false, ticklabelsvisible=false)
    Label(subgrid[3, 1], "Low")
    rowgap!(subgrid, 5)
    resize_to_layout!(fig)
    fig
end

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/e/8/e8bd45c56894bcdc0007d1f0ea771559eeb55c1c.jpeg)

If you don’t constrain the colorbar height the labels will then match the edges of the axis, which can be nice.

 ![image](https://global.discourse-cdn.com/julialang/original/3X/3/e/3e994498100ab9beb5ee46376edf22161afa1f09.jpeg)

---

<div class="post-metadata">

### Author: ![nari](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nari/32/46452_2.png) [@nari](https://discourse.julialang.org/u/nari)
#### Post date: [July 18, 2023, 12:31am UTC](https://discourse.julialang.org/t/makie-colorbar-with-the-high-and-low-labels/101604/3 "2023-07-18T00:31:56Z")

</div>

Amazing, thank you.
