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

**URL:** <https://discourse.julialang.org/t/makie-jl-how-to-choose-a-slice-of-a-colormap-in-colorbar/132279>\
**Category:** Visualization\
**Tags:** plotting, makie\
**Created:** [September 11, 2025, 11:09am UTC](https://discourse.julialang.org/t/makie-jl-how-to-choose-a-slice-of-a-colormap-in-colorbar/132279 "2025-09-11T11:09:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![JaydevSR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jaydevsr/32/31752_2.png) [@JaydevSR](https://discourse.julialang.org/u/JaydevSR)\
**Post date:** [September 11, 2025, 11:09am UTC](https://discourse.julialang.org/t/makie-jl-how-to-choose-a-slice-of-a-colormap-in-colorbar/132279/1 "2025-09-11T11:09:16Z")

</div>

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:

```julia
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.

---

<div class="post-metadata">

**Author:** ![JaydevSR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jaydevsr/32/31752_2.png) [@JaydevSR](https://discourse.julialang.org/u/JaydevSR)\
**Post date:** [September 12, 2025, 9:53am UTC](https://discourse.julialang.org/t/makie-jl-how-to-choose-a-slice-of-a-colormap-in-colorbar/132279/2 "2025-09-12T09:53:49Z")

</div>

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