Creating a heatmap to visualize denisity of 2D point data
14 ビュー (過去 30 日間)
古いコメントを表示
Hello,
I am trying to create a heat map from an Mx2 matrix of point data. The point data represents spatial locations and I am attempting to create a heat map that highlights densely-clustered points from sparsely-clustered points. the data is stored in a variable called points. points(:,1) is x data and points(:,2) is y data. when I type HeatMap(points) I get useless information. Is there a way I can visualize the density of these points in a heat map? I tried hist3, but it doesn't represent the data the way I would like.
Thanks,
Kyle
0 件のコメント
採用された回答
Walter Roberson
2015 年 6 月 19 日
grid = 256; %refinement of map
minvals = min(points);
maxvals = max(points);
rangevals = maxvals - minvals;
xidx = 1 + round((points(:,1) - minvals(1)) ./ rangevals(1) * (grid-1));
yidx = 1 + round((points(:,2) - minvals(2)) ./ rangevals(2) * (grid-1));
density = accumarray([yidx, xidx], 1, [grid,grid]); %note y is rows, x is cols
imagesc(density, 'xdata', [minvals(1), maxvals(1)], 'ydata', [minvals(2), maxvals(2)]);
(This will make the image slightly larger than would be correct. It's probably not worth correcting for.)
3 件のコメント
Cai Chin
2020 年 11 月 15 日
Hi, I am trying to do a very similar thing - I used your code but it only generates a blue frame instead of a colour density map. Instead of having a matrix input, I have 2 vectors 'v' and 'w' which I tried making into a matrix to fit your code.
I was wondering if you wouldn't mind please pointing out what the issue is or suggesting an alternative?
Thanks in advance.
% Convert vectors 'v' and 'w' into a matrix
points = [v, w];
% Generate colourmap of density
grid = 256; %refinement of map
minvals = min(points);
maxvals = max(points);
rangevals = maxvals - minvals;
xidx = 1 + round((points(1) - minvals(1)) ./ rangevals(1) * (grid-1));
yidx = 1 + round((points(2) - minvals(2)) ./ rangevals(2) * (grid-1));
density = accumarray([yidx, xidx], 1, [grid,grid]); %note y is rows, x is cols
imagesc(density, 'xdata', [minvals(1), maxvals(1)], 'ydata', [minvals(2), maxvals(2)]);
set(gca,'YDir','normal');
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Data Distribution Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!