How to do a heat map ( color the surface) in a 2D plot ?
87 views (last 30 days)
Show older comments
Hello,
I have 3 parameters, x, y and z. And I would like to represent z as a colored surface like in the picture.
Here is my code:
dataTG=xlsread('dataTG.xlsx');
IC50A=9456
IC50B=14.75
X=((dataTG(:,2))./IC50A);
Y=((dataTG(:,3))./IC50B);
TT=(dataTG(:,2)./IC50A)+(dataTG(:,3)./IC50B)
z=(10.^((1-(X./TT)).*(1-(Y./TT)).*(0.78369.*(X./TT)+2.0178.*(Y./TT)-1.9924.*(X./TT).*(Y./TT)+4.7444.*(X./TT).*(Y./TT).*((X./TT)-(Y./TT)))));
figure
refline(-1,1)
hold on
pointsize = 10;
scatter(X, Y, pointsize, z)
colorbar()
Then, to do z as a colored surface, I tried :
[X,Y] = meshgrid(X,Y);
surf(z,'EdgeColor','None');
view(2);
but they say it does not work because 'Z must be a matrix, not a scalar or vector'.
Do you have have any idea ?
Thank you for your help.
0 Comments
Answers (2)
KSSV
on 21 Jun 2017
[X,Y] = meshgrid(X,Y);
Z = repmat(z,1,length(x)) ;
surf(X,Y,Z);
shading interp
view(2);
0 Comments
Walter Roberson
on 21 Jun 2017
dataTG=xlsread('dataTG.xlsx');
IC50A=9456
IC50B=14.75
x = ((dataTG(:,2))./IC50A);
y = ((dataTG(:,3))./IC50B);
[X, Y] = meshgrid(x, y);
TT = (X./IC50A) + (y./IC50B);
Z = (10.^((1-(X./TT)).*(1-(Y./TT)).*(0.78369.*(X./TT)+2.0178.*(Y./TT)-1.9924.*(X./TT).*(Y./TT)+4.7444.*(X./TT).*(Y./TT).*((X./TT)-(Y./TT)))));
figure
refline(-1,1)
hold on
pointsize = 10;
surf(X, Y, Z, 'edgecolor', 'none');
colorbar()
0 Comments
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!