Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

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

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

From: yaya yoyo

Date: 18 Feb, 2010 13:43:06

Message: 1 of 5

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

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

From: Sadik

Date: 18 Feb, 2010 15:18:02

Message: 2 of 5

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" <matlab101@walla.co.il> wrote in message <hljg5a$qd3$1@fred.mathworks.com>...
> 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

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

From: Walter Roberson

Date: 18 Feb, 2010 19:12:02

Message: 3 of 5

yaya yoyo wrote:
> 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

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.

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

From: Jerry Gump

Date: 20 May, 2010 20:47:04

Message: 4 of 5

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.


> 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.

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

From: Walter Roberson

Date: 20 May, 2010 21:06:04

Message: 5 of 5

"Jerry Gump" <spppyang@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 ;-)

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us