필터 지우기
필터 지우기

contourf, outside a region

조회 수: 5 (최근 30일)
Uwe Brauer
Uwe Brauer 2017년 10월 24일
댓글: Uwe Brauer 2017년 10월 24일
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
Uwe Brauer
Uwe Brauer 2017년 10월 24일
[SOLVED]
arr, the function I used is wrong, countourf does precisely what it should do.
sorry for the noise
Uwe Brauer

댓글을 달려면 로그인하십시오.

답변 (1개)

Robert U
Robert U 2017년 10월 24일
편집: Robert U 2017년 10월 24일
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
Uwe Brauer
Uwe Brauer 2017년 10월 24일
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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Contour Plots에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by