Plot heatmap with 3 variables

12 Ansichten (letzte 30 Tage)
Bernoulli Lizard
Bernoulli Lizard am 21 Jan. 2013
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.

Antworten (2)

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

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

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!

Translated by