How to annotate on heatmaps in Makie.jl

How to annotate heat maps in Makie.jl.

I was going through this post and the code in the question doesn’t seem to produce the text (numbers) on the heatmap.

The code is also provided below:

using DataFrames
using CSV
using CairoMakie

download("", "flights.csv")
flights = DataFrame(CSV.File("flights.csv"))

data = Array(unstack(flights, :year, :month, :passengers)[!, 2:end])

fig = Figure()
ax = Axis(fig[1, 1], xlabel = "Year", ylabel = "Month")
hm = heatmap!(ax, data)

Colorbar(fig[1, 2], hm)

    position = [Point2f(x, y) for x in 1:12 for y in 1:12],
    align = (:center, :center),
    color = ifelse.(data' .< 400, :white, :black),
    textsize = 14,

save("figure.png", fig)


The error that I get:

Desired output:

Any help is appreciated. Thanks!

Do you need that example in particular?

You could take a look at the BeautifulMakie example which should be up to date

(saying because apart from version changes in makie, that other file could have changed since the original post).


Amazing! The example on the link you provided works perfectly for my case as well. Thanks.

1 Like