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?
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]
It looks like
j are swapped.
ann = [(j, i, text(round(week_day[i, j], digits=2), fontsize, :white, :center)) for i in 1:nrow for j in 1:ncol]
It works, but I didn’t get the issue. “I” is row and “j” is column.
Why here we are indexing with:
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.
Yep. Inderstood. Thats why the tuple needs to be swapped. Very smart