# Why this code can't annote all heatmap cells?

**URL:** <https://discourse.julialang.org/t/why-this-code-cant-annote-all-heatmap-cells/69431>\
**Category:** General Usage\
**Tags:** plotting, plots\
**Created:** [October 8, 2021, 1:01pm UTC](https://discourse.julialang.org/t/why-this-code-cant-annote-all-heatmap-cells/69431 "2021-10-08T13:01:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jcbritobr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jcbritobr/32/219275_2.png) [@jcbritobr](https://discourse.julialang.org/u/jcbritobr)\
**Post date:** [October 8, 2021, 1:01pm UTC](https://discourse.julialang.org/t/why-this-code-cant-annote-all-heatmap-cells/69431/1 "2021-10-08T13:01:06Z")

</div>

Hello, good morning.  
I’m trying o annotate a heatmap, but the labels are going wrong in the map as the figure below shows  
May someone help?

![image](https://global.discourse-cdn.com/julialang/original/3X/c/4/c4989e30986c4b01af5550ec119e2b412a9cae5c.png)

source

```julia
using Plots

week_day = randn(24, 5);

xlabel = ["Mon", "Tue", "Wed", "Thu", "Fri"]

heatmap(week_day, xticks=(1:5, xlabel), yticks=(1:24), fill_z=week_day)

fontsize = 5

nrow, ncol = size(week_day)

ann = [(i, j, text(round(week_day[i, j], digits=2), fontsize, :white, :center)) for i in 1:nrow for j in 1:ncol]

annotate!(ann, linecolor=:white)

```

---

<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 8, 2021, 8:08pm UTC](https://discourse.julialang.org/t/why-this-code-cant-annote-all-heatmap-cells/69431/2 "2021-10-08T20:08:58Z")

</div>

It looks like `i` and `j` are swapped.  
Try:

```julia
ann = [(j, i, text(round(week_day[i, j], digits=2), fontsize, :white, :center)) for i in 1:nrow for j in 1:ncol]

```

---

<div class="post-metadata">

**Author:** ![jcbritobr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jcbritobr/32/219275_2.png) [@jcbritobr](https://discourse.julialang.org/u/jcbritobr)\
**Post date:** [October 9, 2021, 6:45pm UTC](https://discourse.julialang.org/t/why-this-code-cant-annote-all-heatmap-cells/69431/3 "2021-10-09T18:45:32Z")

</div>

It works, but I didn’t get the issue. “I” is row and “j” is column.  
Why here we are indexing with:

```julia
 [(j, i...

```

---

<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 9, 2021, 6:48pm UTC](https://discourse.julialang.org/t/why-this-code-cant-annote-all-heatmap-cells/69431/4 "2021-10-09T18:48:56Z")

</div>

2d plots have the first index along the x-axis and second index along y-axis. That is how `annotate` interprets them. However, Julia matrices (and as plotted by heatmap) have their first index along the “vertical y-axis” and the second index along the “horizontal x-axis”. They are swapped.

---

<div class="post-metadata">

**Author:** ![jcbritobr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jcbritobr/32/219275_2.png) [@jcbritobr](https://discourse.julialang.org/u/jcbritobr)\
**Post date:** [October 9, 2021, 6:54pm UTC](https://discourse.julialang.org/t/why-this-code-cant-annote-all-heatmap-cells/69431/5 "2021-10-09T18:54:48Z")

</div>

Yep. Inderstood. Thats why the tuple needs to be swapped. Very smart 👏 👏
