How can I bring patch in front of a surface plot?
5 次查看(过去 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):
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/322435/image.png)
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!