How can I bring patch in front of a surface plot?
조회 수: 12 (최근 30일)
이전 댓글 표시
Hi!
I am trying to plot a patch on top of a surface plot, but it always go 'behind'. Is there any way to bring it to the front?
figure;
s = surface(m.z, P, A,'edgecolor', 'none')
hold on;
patch([0,0,5.04,5.04], [0, 60, 60, 0], 'red', 'FaceAlpha',.3)
I need to shade an area of the surface plot, so I'd like to have it on top of it. Following you see a simpler but representative example of the problem I am facing, the patch is hidden (see the bottom left corner):
Thank you in advance.
댓글 수: 0
채택된 답변
Star Strider
2020년 6월 26일
The patch call does not define the ‘Z’ level, so by default it is zero. Change that to put it where you want it (this puts it at 10):
zlvl = 10;
patch([0,0,5.04,5.04], [0, 60, 60, 0], ones(1,4)*zlvl, 'red', 'FaceAlpha',.3)
To illustrate:
x = -1:0.1:1;
[X,Y] = ndgrid(x);
Z = X.^2 - Y.^3;
figure
surf(X, Y, Z)
hold on
patch([0 0 0.5 0.5], [0 1 1 0], 'r')
patch([0 0 0.5 0.5]-0.5, [0 1 1 0], ones(1,4)*1.5, 'g')
hold off
grid on
.
댓글 수: 2
Star Strider
2020년 6월 26일
As always, my pleasure!
Define ‘zlvl’ to be whatever you want.
One option is:
zlvl = max(A(:));
to have it above everything else (assuming we are looking at the surface you are plotting from the top down). Define it similarly for other options.
.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Polygons에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!