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

19 次查看(过去 30 天)
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
Adam Danz 2019-10-28
编辑:Adam Danz 2020-12-29
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 = [];
Alternatively, (better than the version above; added Dec 29, 2020)
h = heatmap(rand(600,750));
h.XDisplayData = [];
h.YDisplayData = [];
Or to show every 50 ticks (added Dec 29, 2020)
h = heatmap(rand(600,750));
h.YDisplayData = h.YDisplayData([1,50:50:end]);
h.YDisplayData = h.YDisplayData([1,50:50:end]);
However, I don't recommend using heatmap. 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.
  2 个评论
Ahmed Madhun
Ahmed Madhun 2019-10-29
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
Adam Danz 2019-10-29
Instead of plotting the values using heatmap, use imagesc.
I see that the same suggestion was made in this comment.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Distribution Plots 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by