Plot heatmap with 3 variables
9 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
Jonathan Epperl
2013-1-21
编辑:Jonathan Epperl
2013-1-21
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 个评论
Image Analyst
2013-1-21
编辑:Image Analyst
2013-1-21
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 个评论
另请参阅
类别
在 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!