contourf plot over circular domain

3 views (last 30 days)
Killian Miller
Killian Miller on 12 Jan 2012
Edited: Killian Miller on 19 Jul 2014
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.

Answers (2)

the cyclist
the cyclist on 12 Jan 2012
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 on 18 Jul 2014
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 Comment
Killian Miller
Killian Miller on 19 Jul 2014
Edited: Killian Miller on 19 Jul 2014
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

Sign in to comment.

Categories

Find more on Data Distribution Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!