Plot 2D surface with z axis as colored bar
이전 댓글 표시
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.
답변 (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
Talal Salem
2019년 9월 5일
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.
카테고리
도움말 센터 및 File Exchange에서 Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!