contourf plot over circular domain

19 次查看(过去 30 天)
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 中查找有关 Contour Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by