Heat map of 2-D scatter plot data
Afficher commentaires plus anciens
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 commentaire
per isakson
le 15 Mai 2015
Réponse acceptée
Plus de réponses (1)
Image Analyst
le 15 Mai 2015
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, '*')

Catégories
En savoir plus sur Mathematics dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!