contourf, outside a region
Afficher commentaires plus anciens
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
le 24 Oct 2017
Réponses (1)
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
le 24 Oct 2017
Catégories
En savoir plus sur Blocked Images dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!