# How to add grid lines on top of a heatmap in Makie?

**URL:** https://discourse.julialang.org/t/how-to-add-grid-lines-on-top-of-a-heatmap-in-makie/77578
**Category:** Visualization
**Tags:** makie
**Created:** [March 8, 2022, 11:38am UTC](https://discourse.julialang.org/t/how-to-add-grid-lines-on-top-of-a-heatmap-in-makie/77578 "2022-03-08T11:38:52Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![ForceBru](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/forcebru/32/21389_2.png) [@ForceBru](https://discourse.julialang.org/u/ForceBru)
#### Post date: [March 8, 2022, 11:38am UTC](https://discourse.julialang.org/t/how-to-add-grid-lines-on-top-of-a-heatmap-in-makie/77578/1 "2022-03-08T11:38:52Z")

</div>

I have some code which boils down to `heatmap(matrix, colormap=Reverse(:grays))` and produces this plot:

 ![posteriorMatrix](https://global.discourse-cdn.com/julialang/original/3X/c/e/ce1f4985238659a74e00fd1d831b3b94f02090c9.png)

There’s a lot of white in the plot, and I’d like to emphasize that it’s _not_ empty space, so I wanted to add grid lines to the plot to show that the image actually consists of many rectangles, a lot of which are white. However, I couldn’t find any way of adding grid lines to a heatmap. Initially I thought they were essentially white and thus couldn’t be seen on the plot, so I tried to specify that I need _black_ lines with this theme:

```julia
my_theme = Theme(
    Axis = (
        xgridcolor = :black,
        ygridcolor = :black,
    )
)

```

However, this didn’t change anything. There’s a very similar post [here](https://discourse.julialang.org/t/how-yo-plot-grid-lines-top-of-heatmap-by-using-plots-heatmap/37985), but it’s about Plots.jl, and it doesn’t have any solutions.

Is it possible to add grid lines to a heatmap in Makie?

---

<div class="post-metadata">

### Author: ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)
#### Post date: [March 8, 2022, 12:16pm UTC](https://discourse.julialang.org/t/how-to-add-grid-lines-on-top-of-a-heatmap-in-makie/77578/2 "2022-03-08T12:16:50Z")

</div>

The grid lines are moved backwards in z a bit so the normal plots are on top of them. You can move the heatmap back so it’s behind them. (Or move them forward)

```julia
f, ax, hm = heatmap(randn(100, 100), colormap = :Blues, colorrange = (-2, 8),
  axis = (;
    aspect = DataAspect(),
    xgridcolor = :black,
    ygridcolor = :black,
    xgridwidth = 2,
    ygridwidth = 2,
    xminorgridcolor = :black,
    yminorgridcolor = :black,
    xminorgridvisible = true,
    yminorgridvisible = true,
    xminorticks = IntervalsBetween(5),
    yminorticks = IntervalsBetween(5),
  ))
translate!(hm, 0, 0, -100)
f

```

 ![grafik](https://global.discourse-cdn.com/julialang/original/3X/5/3/5380e4dc182a524524029444a4edc9bf8c7b40bf.png)

---

<div class="post-metadata">

### Author: ![ForceBru](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/forcebru/32/21389_2.png) [@ForceBru](https://discourse.julialang.org/u/ForceBru)
#### Post date: [March 8, 2022, 12:30pm UTC](https://discourse.julialang.org/t/how-to-add-grid-lines-on-top-of-a-heatmap-in-makie/77578/3 "2022-03-08T12:30:52Z")

</div>

Works great, thanks!
