How can I bring patch in front of a surface plot?
12 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Star Strider
il 26 Giu 2020
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 Commenti
Star Strider
il 26 Giu 2020
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.
.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Polygons in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!