Makie.jl: How to choose a slice of a colormap in ColorBar

I am trying to plot a colorbar for my plot where I have used a particular slice of a colormap for different lines. But I can’t figure out how to restrict the colorbar to only display that section of the colormap and not the whole colormap.

Example:

for i in 1:nsites
    lines!(ax, time, values_1, color=i, colormap=:coolwarm, colorrange=(1, 3nsites))
    lines!(ax, time, values_2, color=2nsites+i, colormap=:coolwarm, colorrange=(1, 3nsites)))
end

Colorbar(fig[1, 2], colorrange=(1, nsites),
        colormap = cgrad(:coolwarm, 3nsites, categorical = true), label = "values_1");
Colorbar(fig[1, 3], colorrange=(2nsites, 3nsites),
        colormap = cgrad(:coolwarm, 3nsites, categorical = true), label = "values_2");

I am trying the above but it’s not giving the right results.

Figured it out: It’s possible to slice as cgrad(..)[1:n] which let’s me do what I want.