# Makie: manual colorbar tick values and tick labels

**URL:** <https://discourse.julialang.org/t/makie-manual-colorbar-tick-values-and-tick-labels/130437>\
**Category:** General Usage\
**Tags:** makie\
**Created:** [July 3, 2025, 6:27am UTC](https://discourse.julialang.org/t/makie-manual-colorbar-tick-values-and-tick-labels/130437 "2025-07-03T06:27:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tduretz](https://avatars.discourse-cdn.com/v4/letter/t/bcef8e/32.png) [@tduretz](https://discourse.julialang.org/u/tduretz)\
**Post date:** [July 3, 2025, 6:27am UTC](https://discourse.julialang.org/t/makie-manual-colorbar-tick-values-and-tick-labels/130437/1 "2025-07-03T06:27:14Z")

</div>

Hello,  
I was wondering how to set manual colorbar tick values and tick labels when using categorical colormap in Makie. I have prepared an MWE below. The data I want plot contain numeric values (1, 2, 3, 4) and NaN values. I would like the colorbar tick values to be 1, 2, 3, 4 (omitting NaNs) and the colorbar tick labels to be “a”, “b”, “c”, “d” (again, omitting NaNs) . I have tried using `cbar.ticks` but it did not help so far. Can someone help me with this?

In addition, is there a way to define a background color behind the surface covered by the colorbar region?

```julia
    N = (200, 100) 
    x = LinRange(-2, 2, N[1]) 
    y = LinRange(-1, 1, N[2])
    field = zeros(N...)
    field[1: 50,:] .= 1.0
    field[50:100,:] .= 2.0
    field[100:150,:] .= 3.0
    field[150:200,:] .= 4.0
    field[:,70:100] .= NaN 
    f = Figure()
    ax = Axis(f[1, 1])
    hm = heatmap!(ax, x, y, field, colormap = Makie.Categorical((:vik, 0.8)), colorrange=(1, 4))
    cbar =Colorbar(f, hm, label = L"$$Mechanisms", width = 320, height = 25,
        labelsize = 20, ticklabelsize = 20, bbox=BBox(220, 100, 20, 150),
        alignmode = Outside(20), halign = :left, ticklabelcolor = :black, labelcolor = :black, vertical=false,
        tickcolor = :black)
    cbar.ticks = ([1,2,3,4], ["a","b","c","d"])
    display(f)

```

---

<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 3, 2025, 8:25am UTC](https://discourse.julialang.org/t/makie-manual-colorbar-tick-values-and-tick-labels/130437/2 "2025-07-03T08:25:51Z")

</div>

Looks like `Categorical` overrides ticks without being able to change them after, feels like a bug to me but I don’t like how `Categorical` works, anyway. It’s easier in your case to use a `cgrad(...; categorical = true)` which makes the colorbar render individual facets. Then you can set the color limits to -0.5/+0.5 at the ends and your ticks work.

The background you can do with a nested `GridLayout` and a `Box`, plus `Outside` alignmodes.

```julia
N = (200, 100) 
x = LinRange(-2, 2, N[1]) 
y = LinRange(-1, 1, N[2])
field = zeros(N...)
field[1: 50,:] .= 1.0
field[50:100,:] .= 2.0
field[100:150,:] .= 3.0
field[150:200,:] .= 4.0
field[:,70:100] .= NaN 
f = Figure()
ax = Axis(f[1, 1])
hm = heatmap!(ax, x, y, field, colormap = cgrad(:vik, 4; categorical = true, alpha = 0.8), colorrange=(0.5, 4.5))

grid = GridLayout(f[1, 1], tellwidth = false, tellheight = false, alignmode = Outside(10),
    halign = :right, valign = :bottom)

Box(grid[1, 1], color = :gray80)

cbar = Colorbar(grid[1, 1], hm, label = L"$$Mechanisms", width = 320, height = 25,
    labelsize = 20, ticklabelsize = 20, bbox=BBox(220, 100, 20, 150),
    alignmode = Outside(20), halign = :left, ticklabelcolor = :black, labelcolor = :black, vertical=false,
    tickcolor = :black, ticks = ([1,2,3,4], ["a","b","c","d"]))
f

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/4/2/429b96ddecbfb1965ef2c519bfa15bf01cc6a414.jpeg)
