Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Filling an area in a polar plot, how do I do this?

1,533 views
Skip to first unread message

yaya yoyo

unread,
Feb 18, 2010, 8:43:06 AM2/18/10
to
Hello all,
I want to fill in part of the circle in a polar plot but don't know exactly how to do so?
Specifically, I measured the head direction of an animal and computed the preferred head direction. Which I represent using a polar plot. In addition to this I want to show the confidence interval for my measure (which I also already computed) . The way I wanted to do so, was to highlight this area of the polar plot some how,
In regular plots I can do this using functions such as area and others, but I have no idea how I can do this in the polar plots and would appreciate you help,
Thank you

Sadik

unread,
Feb 18, 2010, 10:18:02 AM2/18/10
to
There could be better solutions but the one that comes to my mind is the following.

If you sample your polar plot densely enough, the you can use patch. It will not be an exact fill but it may look almost filled.

Please do

help patch

Best.

"yaya yoyo" <matl...@walla.co.il> wrote in message <hljg5a$qd3$1...@fred.mathworks.com>...

Walter Roberson

unread,
Feb 18, 2010, 2:12:02 PM2/18/10
to

h = polar([pi/6,pi/5],[1 2]);
paxis = get(h,'Parent');
paxchild = allchild(paxis);
ppatch = paxchild(end);

ppatch will now be the handle of a patch which is the circle of the polar
plot. You can get the patch's XData and YData properties in order to retrieve
the *cartesian* coordinates of the circle (relative to the axis). The
coordinates are counter-clockwise starting from the right-most point on the
circle (x = whatever, y = 0). There will probably be 101 coordinates, with the
last pair being the same as the first. If you have angle alpha degrees, then
it will touch the circle between pairs floor(1 + 100 * alpha / 360) and
ceil(1 + 100 * alpha / 360). You could interpolate the coordinates if you feel
enthusiastic.

With this information, you can create a patch from (0,0) to the first
(counter-clockwise) point, then copy the points from the patch until you reach
the last exact point, then add your interpolated final point, then close back
to (0,0).

Warning: if you are using the OpenGL renderer, in order for the second patch
to appear on top of the patch that is the circle, you must give the second
patch a Z value that is greater than the (implicit 0) Z value of the
background circle. It doesn't matter which of the patches is drawn "first",
and manipulating the axis Children order or using uistack() will not change
this behavior: it is a property of OpenGL that items in the same Z plane are
internally rendered in a specific order.

Jerry Gump

unread,
May 20, 2010, 4:47:04 PM5/20/10
to
Can you do this example?

angle = [0,0,pi/2];
radius = [0, 2, 2];
h = polar(angle,radius);

It is a triangle on a polar plot. How do you fill this triangle with color?

Thanks.

Walter Roberson

unread,
May 20, 2010, 5:06:04 PM5/20/10
to
"Jerry Gump" <sppp...@yahoo.com> wrote in message <ht4748$rt7$1...@fred.mathworks.com>...

> Can you do this example?
>
> angle = [0,0,pi/2];
> radius = [0, 2, 2];
> h = polar(angle,radius);
>
> It is a triangle on a polar plot. How do you fill this triangle with color?

patch( get(h,'XData'), get(h,'YData'), 'g')

Easy ;-)

Dan

unread,
May 28, 2016, 7:16:17 PM5/28/16
to
"yaya yoyo" wrote in message <hljg5a$qd3$1...@fred.mathworks.com>...
I had an assignment recently where I was asked to fill in a shape drawn in polar coordinates. I did so by converting the polar coordinates into cartesian coordinates and then using 'fill':

polar(theta, rho); % Here's what I was given (theta and rho were defined earlier)

[X,Y] = pol2cart(theta,r); % Convert polar to cartesian coordinates

fill(X,Y) % This will fill in your shape.

My answer isn't up to par of many posters on this forum, but I noticed the responses you had received were focussed around using 'patch', which was unfamiliar to me. So here's an alternative.

Kind regards
Message has been deleted

pcfra...@gmail.com

unread,
Jul 27, 2018, 3:44:24 PM7/27/18
to
Hello,

I am currently trying to fill in a shape on a polar plot, and the code above works great. The only issue I am having is that I am trying to put multiple data sets on the polar plot, and the other data uses the 'polarplot' function instead of the polar function. Is there any way to have a dataset that uses the function 'polarplot' and 'polar' on the same graph? If not, is it possible to adjust the code written in the previous comment to work with the 'polarplot' function?

Thanks
0 new messages