Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Threshold on contourf

Tags:

matlab

I want two contour plot to show a threshold and I'm using

contourf(X,Y,Z,[-1,-1],'k');
contourf(X,Y,Z,[2,2],'w');

while X and Y a simple meshgrid.

I see that the matrix Z has values above -1 and above 1, so I'm expecting the two lines at -1 and 1 but I see only the first contour lines. What am I doing wrong? Do I get it wrong this property?

Edit: here an example

x = 0:5:180;
y = 0:5:355;
[X,Y] = meshgrid(x,y);
Z = 5*cos(X);

figure(1);## Heading ##
surf(X',Y',Z','EdgeColor','none');
view(2); colorbar;colormap(jet); hold on
contour(X',Y',Z',[-1,-1],'k','LineWidth',1);
contour(X',Y',Z',[2,2],'k','LineWidth',2);
legend('','1','2','Location','northeastoutside');

I saw that if I put the two contour in a new figure, the two are plotted. But when I use surf, I just see the [-1,-1] option. Many thanks

edit2: using pcolor instead of surf (removing ,'EdgeColor','none') gives me the correct plot...Why? What changes?

like image 927
Shika93 Avatar asked Apr 23 '26 09:04

Shika93


1 Answers

What happens is that contourf is not a 3D ploting function, its a 2D plotting function. So when you ask to plot contour lines, it will always plot them at z=0. So your surf plot is "on top of" the contourf for z>0, as you are setting view(2).

Look at the example you gave, with a different view:

enter image description here

You can see both lines here.

pcolor plots a 2D image, not a 3D surface, so it works with pcolor or imagesc.

like image 92
Ander Biguri Avatar answered Apr 25 '26 01:04

Ander Biguri



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!