Plot 2D surface with z axis as colored bar
4 次查看(过去 30 天)
显示 更早的评论
Hi all,
I'm trying to write a code to plot the attached figure. Basically, my X values will vary between 2.99 and 3.23 with corresponding Z values varied from 3.3 to 3.7, while my Y values is not important here. My main idea is to present the variation in Z values as a colored map. I am wondering if anyone has an idea on how to draw such plot.
0 个评论
回答(1 个)
Star Strider
2019-9-5
Example —
M = peaks(20); % Data For Plot
figure
[c,h] = contourf(M);
h.LineStyle = 'none';
or:
figure
subplot(2,1,1)
[c,h] = contourf(M);
h.LineStyle = 'none';
Ax1 = gca;
sp1 = Ax1.Position;
Ax1.Position = sp1 + [0 0 -0.1 0];
subplot(2,1,2)
[c,h] = contourf(M);
h.LineStyle = 'none';
Ax2 = gca;
sp2 = Ax2.Position;
Ax2.Position = sp2 + [0 0 -0.1 0];
hc2 = colorbar;
hcp2 = hc2.Position;
hc2.Position = hcp2 + [0.15 0 0 hcp2(4)*1.4]
2 个评论
Star Strider
2019-9-5
You need to use a different interpolation method:
zz = griddata(x, y, z, xx, yy, 'v4');
The 'nearest' method will also work.
If you want to use any other method, you need to set the NaN values (that comprise all except the diagonal of ‘zz’ with all the other methods) to some definite numerical value, for example:
zz = griddata(x, y, z, xx, yy);
zz(isnan(zz)) = 0;
Experiment to get the result you want.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spline Postprocessing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!