I have a set of 2D coordinate data for 5598 points (attached) and I want to plot a heatmap to show their density distribution.First I plot the histogram by:
D=dlmread('PC1-PC2.txt');X=D(:,1);Y=D(:,2);H=histogram2(X,Y,37);
and I get fig1 (attached) the h with the follow information:
Data: [5598x2 double] Values: [37x37 double] NumBins: [37 37] XBinEdges: [1x38 double] YBinEdges: [1x38 double] BinWidth: [0.1310 0.1390] Normalization: 'count' FaceColor: 'auto' EdgeColor: [0.1500 0.1500 0.1500] The range of h.XbinEdges is -2.3 to 2.5; and the range of h.YbinEdges is -2.8 to 2.3
and a 37 x 37 matrix counts by:
counts = h.Values
After that I applied every value in the matrix "counts" to an equation, and got my target 37 by 37 matrix "G" (attached), and then I plot the heatmap
imshow(heatMap, []);axis on;colormap(hot(256));colorbar;
and I got fig2 (attached)
In order to make the image larger and smoother, I used the following codes:
heatMap = imresize(G, [700, 700])imshow(heatMap, []);axis on;colormap(hot(256));colorbar;
Now the image was close to what I want, but the X and y axes ranges (0 to 7000) are meanless. I hope the axes ranges can reflect the ranges of the original coordinate data, just like the histogram (fig1): x axis range -2.3 to 2.5 and y axis range -2.8 to 2.3. So I passed these range to imshow:
imshow(heatMap, 'XData',[-2.3 2.5],'YData',[-2.8,2.3]); axis on; colorbar; colormap(hot(256));
and I got fig4 (attached)
Obviously the image is wrong. Is it possible to obtain a image like fig3 but have correct axes ranges like fig4?
Best Answer