# Plots.jl, colorbar tick labels

**URL:** <https://discourse.julialang.org/t/plots-jl-colorbar-tick-labels/69632>\
**Category:** General Usage\
**Tags:** plots\
**Created:** [October 12, 2021, 2:48pm UTC](https://discourse.julialang.org/t/plots-jl-colorbar-tick-labels/69632 "2021-10-12T14:48:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gravlax](https://avatars.discourse-cdn.com/v4/letter/g/dbc845/32.png) [@Gravlax](https://discourse.julialang.org/u/Gravlax)\
**Post date:** [October 12, 2021, 2:48pm UTC](https://discourse.julialang.org/t/plots-jl-colorbar-tick-labels/69632/1 "2021-10-12T14:48:51Z")

</div>

Hi everyone,  
I was wondering whether there is a possibility to define colorbar tick labels manually with Plots.j?  
By this, I mean something like this:  
 ![](https://global.discourse-cdn.com/julialang/original/3X/2/5/252096ed59e3d11d9df87912e84301b5296866bc.png)  
The possibility of passing a `Dict` that maps numerical values to text labels as colorbar tick labels could be quite handy (if it is not already possible :D).  
cheers!

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [October 12, 2021, 8:37pm UTC](https://discourse.julialang.org/t/plots-jl-colorbar-tick-labels/69632/2 "2021-10-12T20:37:40Z")

</div>

Not exactly what you have asked for, but just in case, `Plots.jl` allows displaying a colorbar title that might help. Illustration using the `pyplot()` backend:

 ![Plots_pyplot_colorbar_title](https://global.discourse-cdn.com/julialang/original/3X/e/9/e9b16c1b1698d6919226efbd9dbec6a892dd7933.png)

---

<div class="post-metadata">

**Author:** ![Gravlax](https://avatars.discourse-cdn.com/v4/letter/g/dbc845/32.png) [@Gravlax](https://discourse.julialang.org/u/Gravlax)\
**Post date:** [October 13, 2021, 8:12am UTC](https://discourse.julialang.org/t/plots-jl-colorbar-tick-labels/69632/3 "2021-10-13T08:12:02Z")

</div>

Thanks, that’s already quite interesting.  
Below is a MWE. Basically, I thought it would be nice to use the Dict `flag_colors` to annotate the colorbar. Not sure whether this is possible…

```julia
using Plots

# Data
nx, ny = 31, 31
tab = fill(1, nx, ny)
tab[Int(ceil(nx/3)):end,:] .= 2
tab[Int(ceil(2*nx/3)):end,:] .= 3

# Color palette
cmap = zeros(RGB{Float64}, 3)
cmap[1] = RGB{Float64}( 6/255, 7/255, 9/255) # black
cmap[2] = RGB{Float64}(233/255,214/255, 64/255) # yellow
cmap[3] = RGB{Float64}(198/255, 34/255, 49/255) # red

# Labels
labels = ("Black", "Red", "Yellow")
flag_colors = Dict( 1:3 .=> labels )

display(heatmap(tab', c=palette(cmap,3)) )

```

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [October 13, 2021, 8:42am UTC](https://discourse.julialang.org/t/plots-jl-colorbar-tick-labels/69632/4 "2021-10-13T08:42:32Z")

</div>

For the `pyplot()` backend of `Plots.jl` please check this [posted issue](https://github.com/JuliaPlots/Plots.jl/issues/3174#issuecomment-806313344). Copying the author @isentropic for feedback.

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [May 3, 2025, 10:32pm UTC](https://discourse.julialang.org/t/plots-jl-colorbar-tick-labels/69632/5 "2025-05-03T22:32:44Z")

</div>

Fyi, here is a possible solution using Plots.jl:

 ![Plots_flag_with_colorbar_tickmarks](https://global.discourse-cdn.com/julialang/original/3X/4/e/4e569b06aaf7d8a45b222bfd842c65ffd5a95d05.png)

> **Edited code**
>
> ```julia
> using Plots; gr()
> 
> # Data
> nx, ny = 31, 31
> tab = fill(1, nx, ny)
> tab[Int(ceil(nx/3)):end,:] .= 2
> tab[Int(ceil(2*nx/3)):end,:] .= 3
> 
> # Color palette
> cmap = zeros(RGB{Float64}, 3)
> cmap[1] = RGB{Float64}( 6/255, 7/255, 9/255) # black
> cmap[2] = RGB{Float64}(233/255,214/255, 64/255) # yellow
> cmap[3] = RGB{Float64}(198/255, 34/255, 49/255) # red
> 
> # Labels
> labels = ("Black", "Yellow", "Red")
> flag_colors = Dict( 1:3 .=> labels )
> 
> p1 = heatmap(tab', c=palette(cmap,3), colorbar=false, framestyle=:none)
> 
> data2 = collect(range(extrema(tab')..., 100))
> sdic = sort(flag_colors, by=first)
> p2 = heatmap([1], data2, [data2;;], colorbar=false, c=palette(cmap,3), xaxis=false, tick_direction=:out,
> ymirror=true, yticks=(keys(sdic), values(sdic))
> )
> 
> l = @layout [a{0.95w} b]
> plot(p1, p2, layout=l)
> 
> ```
