Plot heatmap with 3 variables

조회 수: 23 (최근 30일)
Bernoulli Lizard
Bernoulli Lizard 2013년 1월 21일
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.

답변 (2개)

Jonathan Epperl
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

Image Analyst
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.

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by