Heat map of 2-D scatter plot data
이전 댓글 표시
I have a n by 2 matrix called new_data, and I want to make a heat map plotting density of scatter distribution.
I want to add values varying from 0 to 1 to another array called z that has size of (xmax-xmin,ymax-ymin) in which value of 1 would be added to the z component that matches x and y coordinate and add values less than 1 as the distance from the coordinates increase (kind of like dropping ink on paper, and less ink with increasing distance from epicenter).
Here's my code til now:
x = new_data(:,1);
y = new_data(:,2);
z = zeros(round(max(x)) - round(min(x)), round(max(y)) - round(min(y)));
for i = 1:size(new_data,1);
x(i) = x(i) - min(x);
y(i) = y(i) - min(y);
end
for i = 1:size(new_data,1);
z(round(x(i)),round(y(i))) = z(round(x(i)),round(y(i))) + 1;
end
Could anyone help me with this Gaussian value addition or provide any other ideas for plotting scatter density?
댓글 수: 1
per isakson
2015년 5월 15일
채택된 답변
추가 답변 (1개)
Image Analyst
2015년 5월 15일
If you have the Image Processing Toolbox, perhaps one way is to use the distance transform:
numPoints = 30;
x = rand(1,numPoints);
y = rand(1, numPoints);
rows = 240;
columns = 320;
binaryImage = false(rows, columns);
for k = 1 : length(x);
r = ceil(rows * y(k));
c = ceil(columns * x(k));
binaryImage(r, c) = true;
end
imshow(binaryImage);
edm = bwdist(binaryImage);
edmMax = max(edm(:));
edm = edmMax - edm;
imshow(edm, []);
colormap(hot(256));
colorbar;
hold on;
scatter(columns * x, rows * y, '*')

카테고리
도움말 센터 및 File Exchange에서 MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!