# Heatmap plotting incorrect, black lines on X and Y axis outside the figure itself

5 views (last 30 days)
Ahmed Madhun on 28 Oct 2019
Commented: Adam Danz on 29 Oct 2019
I implemented the minutia heat map presented in this paper (page 7): https://arxiv.org/pdf/1909.09901.pdf
For this, the following code is implemented: (X, Y, and A data is attached in a .dat file)
function HeatMapCreator()
% Start plotting minutia
[X, Y, A] = GetMinData("TestData");
% Count Minutiea
n = length(X);
% set Width and Hight
W = 600; H = 750; K = 6;
% Create the matixes
MM = cell(K, 1);
M = zeros(H,W);
% Define the gussian paramater
GP = 2*2^2;
% Go through each pixel
for k = 1:6
for j = 1 : H
for i = 1 : W
Hijk = 0;
for t = 1 : n
Xt = X(t);
Yt = Y(t);
At = A(t);
%Calculate Cs
ED = sqrt((i-Xt)^2+(j-Yt)^2);
Cs = exp(-ED/GP);
%Calculate Co
DO = At - (2 * k * pi / K);
if (DO < -pi) || (DO > pi)
DO = 2 * pi - DO;
end
Co = exp(-DO/GP);
Hijk = Hijk + (Cs * Co);
end
M(j,i) = Hijk;
end
end
MM{k} = M;
end
% Show the 6 figures
for k = 1:6
figure(k)
heatmap(MM{k},'Colormap',gray,'GridVisible','off');
end
end
The following bugs does not make sense:
1- I am getting Black lines in the X and Y axis when plotting:
2- According to the paper, all 6 heatmaps should look different, as here:
But im my code, the matrixes are different from each other, but the heatmap is the same for all the 6 figues. I wonder weather the heat map function have anything to do regarding this error ?
All my figures looks like the first image.

Adam Danz on 28 Oct 2019
Edited: Adam Danz on 28 Oct 2019
Problem 1: the black lines
Those black lines are merely 100s of tick labels (or, the equivalent of axis ticks in Heatmap) . Your data seems to be a matrix with size [750, 600] which means there are a few hundred ticks on each axis, all squished together. Notice the layers of ticks become thicker as ticks move from 1s to 10s to 100s. The problem can be recreated with this line of code:
heatmap(rand(750,600))
To remove the axis ticks,
h = heatmap(rand(600,750));
hs = struct(h); % See warning in command window
hs.XAxis.TickValues = [];
hs.YAxis.TickValues = [];
However, I don't recommend using heatmap at all of this plot. Instead, I think imagesc() would be the better choice.
Problem 2: All plots look the same
It's tough to troubleshoot that one without seeing the data, your plots, or stepping through your code. If I were you, I'd follow these steps:
1. Run the code to produce 1 figure
2. Look into the data and find position within the matix where the values should indicate white areas of the plot. The function find() will come in handy.
3. Then find those location on the plot to confirm that they aren't white. If you use imagesc() note that the y-axis is reversed by default (as it is in Heatmap). If you'd like to flip it to normal: set(gca, 'YDir', 'Normal')
4. Then repeat the process for the 2nd plot and so on. If you find values that represent white, those areas should be white on your plot.

Ahmed Madhun on 29 Oct 2019
Thanks for your answer, i think the first problem is solved, and i am looking on the second one. But how do you mean imagesc() can be used in thiss case. (Step 3 of what you mentioned)
Adam Danz on 29 Oct 2019
Instead of plotting the values using heatmap, use imagesc.
I see that the same suggestion was made in this comment.