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!