How can I bring patch in front of a surface plot?

조회 수: 12 (최근 30일)
gpr
gpr 2020년 6월 26일
댓글: Star Strider 2020년 6월 26일
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.

채택된 답변

Star Strider
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
gpr
gpr 2020년 6월 26일
that's cool, thanks. In that case, I am wondering: what if I want to shade z>10? with your method you define the maximum z, what if I want it to appear for z>10?
Star Strider
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 CenterFile Exchange에서 Polygons에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by