Effacer les filtres
Effacer les filtres

contourf plot over circular domain

5 vues (au cours des 30 derniers jours)
Killian Miller
Killian Miller le 12 Jan 2012
Modifié(e) : Killian Miller le 19 Juil 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.

Réponses (2)

the cyclist
the cyclist le 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 le 18 Juil 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 commentaire
Killian Miller
Killian Miller le 19 Juil 2014
Modifié(e) : Killian Miller le 19 Juil 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

Connectez-vous pour commenter.

Catégories

En savoir plus sur Contour Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by