How to plot heat maps with grid lines in `Plots.jl` with `GR` as backend?

For example, the following code will produce a heat map:

using Plots

heatmap(rand(4, 4))

How do I add the grid lines between each of the squares? The option grid = true does not work.

You can use vline! and hline!:

using Plots

M = rand(4, 5)
heatmap(M)
m, n = size(M)
vline!(0.5:(n+0.5), c=:black)
hline!(0.5:(m+0.5), c=:black)

And the usual line attributes: ls=:dash, etc.

1 Like