Plot heatmap with 3 variables
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have x,y, z data, where x and y are coordinates, and z is the measured value. How can I created a 2D plot, where low values of z are represented by one color, and higher values are represented by darker colors.
0 Kommentare
Antworten (2)
Jonathan Epperl
am 21 Jan. 2013
Bearbeitet: Jonathan Epperl
am 21 Jan. 2013
I suggest imagesc(), for instance:
% Your x-axis
x = linspace(0,2*pi);
% y-axis
y = linspace(0,2*pi);
% a mesh because
[X,Y] = meshgrid(x,y);
% you need data at every possible x-y combination
Z = sin(X).*atan(Y);
% that scales the Z-values and plots a heatmap
imagesc(x,y,Z)
% choose a colormap of your liking
colormap hot
0 Kommentare
Image Analyst
am 21 Jan. 2013
Bearbeitet: Image Analyst
am 21 Jan. 2013
Turn your data into an image, say a 100 by 100 image. Then display with imshow() or image() and then use colormap() and colorbar. Something like this (untested):
minx = min(x);
maxx = max(x);
miny = min(y);
maxy = max(y);
meanValue = mean(z);
heatMapImage = meanValue * ones(100, 100);
for k = 1 : length(x)
column = round( (x(k) - xmin) * 100 / (maxx-minx) ) + 1;;
row = round( (y(k) - ymin) * 100 / (maxy-miny) ) + 1;
heatMapImage(row, column) = z(k);
end
imshow(heatMapImage, []);
colormap('hot');
colorbar;
Any unassigned values (like you don't have every single possible x and y value in your data) will be set to the mean value of what data you do have.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Data Distribution Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!