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?
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)