contourf plot over circular domain

조회 수: 3 (최근 30일)
Killian Miller
Killian Miller 2012년 1월 12일
편집: Killian Miller 2014년 7월 19일
Hello,
I am using the following code in Matlab R2007b to produce a contourf plot of a function that is defined on the unit disk.
[th,rad] = meshgrid((0:5:360)*pi/180,0:0.01:1);
[X,Y] = pol2cart(th,rad);
Z = (1-X)./(X.^2+Y.^2-X+1);
F = sqrt((1-Z+Z.*X).^2+(Z.*Y).^2);
v = linspace(0,1,21); v = v(1:end-1);
v = [v 0.97 0.99 1];
contourf(X,Y,F,v)
axis square
colormap(gray)
colorbar
Everything works fine except for an unwanted black horizontal line (x,0) for 0 <= x <= 1 that appears on the figure. I assume this has something to do with how I am defining my domain. Any tips on how to remove this line would be greatly appreciated. Thanks.

답변 (2개)

the cyclist
the cyclist 2012년 1월 12일
Here are a couple ways:
1. You could turn off the the display of those lines (i.e the contours themselves), and then plot a circle around the perimeter to help differentiate the lighter areas from the background:
set(get(gca,'Children'),'LineStyle','none')
hc=circle(0,0,1,72);
set(hc,'Color','k')
Here I used the following simple function to draw the circle (I think I got it from the FEX ages ago):
function h = circle(x,y,r,nsegments)
if nargin<4
nsegments=50;
end
hold on
th = 0:2*pi/nsegments:2*pi;
xunit = r * cos(th) + x;
yunit = r * sin(th) + y;
h = plot(xunit, yunit);
hold off
end
2. You could just deemphasize the lines by making them the dotted style:
set(get(gca,'Children'),'LineStyle',':')

tomas
tomas 2014년 7월 18일
Hello,
I'm dealing with the same problem - unwanted horizontal line. Proposed procedure has effect on all lines but unfortunately the rest of isolines are desired. Have you solved this problem or is there anybody who can help?
Thanks in advance!
  댓글 수: 1
Killian Miller
Killian Miller 2014년 7월 19일
편집: Killian Miller 2014년 7월 19일
Hi Thomas, I was able to solve this problem. Here is what I did.
x = -1:0.001:1;
[X,Y] = meshgrid(x,x);
C = X.^2+Y.^2;
I = (C >= 1);
F = some function over X and Y
F(I) = c; % c >= max of F over unit disk
contourf(X,Y,F)
colorbar
axis square
axis([-1 1 -1 1])
I hope this helps. Let me know if you have any questions.
Cheers, Killian

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by