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!