contourf, outside a region

1 vue (au cours des 30 derniers jours)
Uwe Brauer
Uwe Brauer le 24 Oct 2017
Commenté : Uwe Brauer le 24 Oct 2017
Hi
I am using contourf to plot a contour of a complex function. See the image below. However I would like to fill the outside of the region, the complement of the green region in the image. How can I achieve that?
regards
Uwe Brauer
The code is the following
if true
x0 = -3;x1 = 3;Nx = 301;y0 = -3;y1 = 3;Ny = 301;
xv= linspace(x0,x1,Nx);
yv= linspace(y0,y1,Ny);
[x,y] = meshgrid(xv,yv);
z = x + i*y;
f1=@(z)[1 - (2/3)*z+(1/6)*z.^2];
f2=@(z)[1+ (1/3)*z];
g2=feval(f1,z);
g1=feval(f2,z);
g=g1./g2;
gmag = abs(g);
contourf(x,y,gmag,[1 1],'b-');
axis([x0,x1,y0,y1]);
axis('square');
grid on;
print -dpng regionabs.png
end
  1 commentaire
Uwe Brauer
Uwe Brauer le 24 Oct 2017
[SOLVED]
arr, the function I used is wrong, countourf does precisely what it should do.
sorry for the noise
Uwe Brauer

Connectez-vous pour commenter.

Réponses (1)

Robert U
Robert U le 24 Oct 2017
Modifié(e) : Robert U le 24 Oct 2017
Hi Uwe,
while Mischa Kim is changing the background color to some RGB triplet value (in this particular case 'yellow') one can use the contourf levels as well:
lastlvl = 1;
contourf(x,y,gmag,[0:(lastlvl-1) 0:(lastlvl-1)],'b-');
hold on
contourf(x,y,gmag,[lastlvl lastlvl],'b-');
axis([x0,x1,y0,y1]);
axis('square');
grid on;
Parameter 'lastlvl' can be changed in order to see more contour levels.
The advantage of this solution is: the area color outside changes with the chosen colormap accordingly.
Kind regards,
Robert
  1 commentaire
Uwe Brauer
Uwe Brauer le 24 Oct 2017
Hi Robert
taht is a nice solution, thank you.
Although I have to admit that my question was wrong since I plotted the wrong function it is very useful to know your trick, since I might need it in the future.
thanks
Uwe

Connectez-vous pour commenter.

Catégories

En savoir plus sur Contour Plots dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by