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:
how to relocate the pie chart on a figure?

Subject: how to relocate the pie chart on a figure?

From: Amy Wang

Date: 22 Sep, 2008 12:29:02

Message: 1 of 15

I first have a figure drawn with imagesc. Then I would like to plot a pie chart at a certain position on the previous figure. How can I do this? Till now, everytime I tried, the pie chart is always at the corner (0,0) of the figure.

Thanks in advance!!

Subject: how to relocate the pie chart on a figure?

From: someone

Date: 22 Sep, 2008 13:49:01

Message: 2 of 15

"Amy Wang" <amy.wang@ua.ac.be> wrote in message <gb832e$o34$1@fred.mathworks.com>...
> I first have a figure drawn with imagesc. Then I would like to plot a pie chart at a certain position on the previous figure. How can I do this? Till now, everytime I tried, the pie chart is always at the corner (0,0) of the figure.
>
> Thanks in advance!!

% after usiing the pie command, then:

set(gca,'Position',[left bottom width height])

% see Axes Properties for more info.

Subject: how to relocate the pie chart on a figure?

From: Amy Wang

Date: 22 Sep, 2008 14:08:01

Message: 3 of 15

I've tried that, but it seems not to work :(

for example:
figure(), imagesc(R), colormap gray, axis equal
% my figure is 64-by-64 pixels
hold on
pie([2 8])
% the pie figure is at the corner
set(gca,'Position',[10 50 6 6])

but then the whole figure disappear?!
or is there something i understood wrong?

thanks in advance!


"someone " <someone@somewhere.net> wrote in message <gb87od$geg$1@fred.mathworks.com>...
> "Amy Wang" <amy.wang@ua.ac.be> wrote in message <gb832e$o34$1@fred.mathworks.com>...
> > I first have a figure drawn with imagesc. Then I would like to plot a pie chart at a certain position on the previous figure. How can I do this? Till now, everytime I tried, the pie chart is always at the corner (0,0) of the figure.
> >
> > Thanks in advance!!
>
> % after usiing the pie command, then:
>
> set(gca,'Position',[left bottom width height])
>
> % see Axes Properties for more info.

Subject: how to relocate the pie chart on a figure?

From: Walter Roberson

Date: 22 Sep, 2008 14:14:40

Message: 4 of 15

Amy Wang wrote:
> % the pie figure is at the corner
> set(gca,'Position',[10 50 6 6])
 
> but then the whole figure disappear?!

What Units is your axes Position in? Chances are the Units is 'normalized'
at the time you try that, so you are positioning to 50 times off the screen.

Subject: how to relocate the pie chart on a figure?

From: Amy Wang

Date: 22 Sep, 2008 14:28:01

Message: 5 of 15

Walter Roberson <roberson@hushmail.com> wrote in message <LKNBk.8164$tp1.1491@newsfe06.iad>...
> Amy Wang wrote:
> > % the pie figure is at the corner
> > set(gca,'Position',[10 50 6 6])
>
> > but then the whole figure disappear?!
>
> What Units is your axes Position in? Chances are the Units is 'normalized'
> at the time you try that, so you are positioning to 50 times off the screen.

I tried with this
set(gca,'Units','pixels','Position',[10 50 6 6])

still I see nothing >"<
how should I fix this?

thanks in advance!

Subject: how to relocate the pie chart on a figure?

From: Amy Wang

Date: 22 Sep, 2008 14:31:01

Message: 6 of 15

Walter Roberson <roberson@hushmail.com> wrote in message <LKNBk.8164$tp1.1491@newsfe06.iad>...
> Amy Wang wrote:
> > % the pie figure is at the corner
> > set(gca,'Position',[10 50 6 6])
>
> > but then the whole figure disappear?!
>
> What Units is your axes Position in? Chances are the Units is 'normalized'
> at the time you try that, so you are positioning to 50 times off the screen.

I tried with this
set(gca,'Units','pixels','Position',[10 50 6 6])

still I see nothing >"<
how should I fix this?

thanks in advance!

Subject: how to relocate the pie chart on a figure?

From: someone

Date: 22 Sep, 2008 16:31:02

Message: 7 of 15

"Amy Wang" <amy.wang@ua.ac.be> wrote in message <gb8a75$j99$1@fred.mathworks.com>...
> Walter Roberson <roberson@hushmail.com> wrote in message <LKNBk.8164$tp1.1491@newsfe06.iad>...
> > Amy Wang wrote:
> > > % the pie figure is at the corner
> > > set(gca,'Position',[10 50 6 6])
> >
> > > but then the whole figure disappear?!
> >
> > What Units is your axes Position in? Chances are the Units is 'normalized'
> > at the time you try that, so you are positioning to 50 times off the screen.
>
> I tried with this
> set(gca,'Units','pixels','Position',[10 50 6 6])
>
> still I see nothing >"<
> how should I fix this?
>
> thanks in advance!

% Here's what I get:

figure()
pie([2 8])
>> get(gca,'Position')

ans =

    0.1300 0.1100 0.7750 0.8150

% Note: units are normalized (the default)

set(gca,'Position',[0.11 0.11 0.775 0.815])

% pie chart shifts slightly to the left

set(gca,'Position',[0.11 0.09 0.775 0.815])

% pie chart shifts slightly down

set(gca,'Position',[0.11 0.11 0.5 0.5])

% pie chart shrinks
% etc.,

Subject: how to relocate the pie chart on a figure?

From: Amy Wang

Date: 23 Sep, 2008 07:02:01

Message: 8 of 15

If it's just the pie chart, then I have no problem moving it. But with an image at the bottom, I can not let the image stay still but move only the pie chart >"<

% my example
figure(), imagesc(R), colormap gray, axis equal
hold on, pie([2 8])


if I use the get(gca...) and set(gca...), I will move the whole thing altogether. Is there a way to solve this?

thanks in advance!

"someone " <someone@somewhere.net> wrote in message <gb8h86$9a0$1@fred.mathworks.com>...
> "Amy Wang" <amy.wang@ua.ac.be> wrote in message <gb8a75$j99$1@fred.mathworks.com>...
> > Walter Roberson <roberson@hushmail.com> wrote in message <LKNBk.8164$tp1.1491@newsfe06.iad>...
> > > Amy Wang wrote:
> > > > % the pie figure is at the corner
> > > > set(gca,'Position',[10 50 6 6])
> > >
> > > > but then the whole figure disappear?!
> > >
> > > What Units is your axes Position in? Chances are the Units is 'normalized'
> > > at the time you try that, so you are positioning to 50 times off the screen.
> >
> > I tried with this
> > set(gca,'Units','pixels','Position',[10 50 6 6])
> >
> > still I see nothing >"<
> > how should I fix this?
> >
> > thanks in advance!
>
> % Here's what I get:
>
> figure()
> pie([2 8])
> >> get(gca,'Position')
>
> ans =
>
> 0.1300 0.1100 0.7750 0.8150
>
> % Note: units are normalized (the default)
>
> set(gca,'Position',[0.11 0.11 0.775 0.815])
>
> % pie chart shifts slightly to the left
>
> set(gca,'Position',[0.11 0.09 0.775 0.815])
>
> % pie chart shifts slightly down
>
> set(gca,'Position',[0.11 0.11 0.5 0.5])
>
> % pie chart shrinks
> % etc.,

Subject: how to relocate the pie chart on a figure?

From: Walter Roberson

Date: 23 Sep, 2008 16:26:36

Message: 9 of 15

Amy Wang wrote:
> If it's just the pie chart, then I have no problem moving it. But with an
> image at the bottom, I can not let the image stay still but move only
> the pie chart >"<

> % my example
> figure(), imagesc(R), colormap gray, axis equal
> hold on, pie([2 8])

Draw the pie chart first, and hold on. The pie chart will establish a coordinate
system with X and Y each running from -1 to +1, with (0,0) at the center.
Figure out where you want your image to appear on that relative scale,
both the lower left and upper right coordinates needed. Then
imagesc([lowerleftx upperrightx], [lowerlefty upperrighty], R)
If necessary, use uistack() or equivalent to move the image to the
bottom.

Technical note: the [x,y] coordinates you provide to imagesc will be
used for the -center- of the lower left and upper right pixels, so if a
half-pixel difference in position and size makes a difference, take
that in to account when calculating the proper image position.


A pie chart returns a list of text() and patch() handles (alternating
in sequence), one pair for each wedge. The text() coordinates are in 'data'
units. A patch() has no explicit units, but in the case of pie() the
values will be in the [-1,+1] x [-1,+1] coordinate system. In order to move
the patch() [if you want to take that approach instead of moving the
image) you would probably be best to adjust the Vertices property of the
patch, adding the constant x and y shifts to each row. Unfortunately if you
take this approach, you need to do it for each patch() and you need to
adjust the Position of each text() object.

Subject: how to relocate the pie chart on a figure?

From: Amy Wang

Date: 24 Sep, 2008 11:46:01

Message: 10 of 15

Thanks for the advice. However, we would like to draw more than one pie chart over our image (say "R" for example on my previous message). Therefore it would be easier if we know how to move the pie chart.

You mentioned "adjust the Vertices property of the patch, adding the constant x and y shifts to each row", can you explain a bit more? I looked through HELP in MATLAB but still have trouble understanding using this axes_handle.

Thank you in advance!

Walter Roberson <roberson@hushmail.com> wrote in message <lM8Ck.41314$PK.9504@newsfe04.iad>...
> Amy Wang wrote:
> > If it's just the pie chart, then I have no problem moving it. But with an
> > image at the bottom, I can not let the image stay still but move only
> > the pie chart >"<
>
> > % my example
> > figure(), imagesc(R), colormap gray, axis equal
> > hold on, pie([2 8])
>
> Draw the pie chart first, and hold on. The pie chart will establish a coordinate
> system with X and Y each running from -1 to +1, with (0,0) at the center.
> Figure out where you want your image to appear on that relative scale,
> both the lower left and upper right coordinates needed. Then
> imagesc([lowerleftx upperrightx], [lowerlefty upperrighty], R)
> If necessary, use uistack() or equivalent to move the image to the
> bottom.
>
> Technical note: the [x,y] coordinates you provide to imagesc will be
> used for the -center- of the lower left and upper right pixels, so if a
> half-pixel difference in position and size makes a difference, take
> that in to account when calculating the proper image position.
>
>
> A pie chart returns a list of text() and patch() handles (alternating
> in sequence), one pair for each wedge. The text() coordinates are in 'data'
> units. A patch() has no explicit units, but in the case of pie() the
> values will be in the [-1,+1] x [-1,+1] coordinate system. In order to move
> the patch() [if you want to take that approach instead of moving the
> image) you would probably be best to adjust the Vertices property of the
> patch, adding the constant x and y shifts to each row. Unfortunately if you
> take this approach, you need to do it for each patch() and you need to
> adjust the Position of each text() object.

Subject: how to relocate the pie chart on a figure?

From: Walter Roberson

Date: 24 Sep, 2008 19:14:16

Message: 11 of 15

Amy Wang wrote:
> we would like to draw more than one pie chart over our image (say "R" for example
> on my previous message). Therefore it would be easier if we know how to move the
> pie chart.
 
> You mentioned "adjust the Vertices property of the patch, adding the constant
> x and y shifts to each row", can you explain a bit more?

e.g.,

Piehandles = movepieto( pie(DataToPlot), Newx, Newy );

function piehandles = movepieto( piehandles, newx, newy );
  %assume pairs, patch first then text
  for K = 1:2:length(piehandles)
    set(piehandles(K), 'Vertices', ...
          bsxfun(@plus, get(piehandles(K), 'Vertices'), [newx newy]) );
    set(piehandles(K+1), 'Position', get(piehandles(K+1),'Position') + [newx, newy, 0]);
  end
end


Note that this only does linear shifts of the pie chart and does not resize it.
It would be trivial to add a scaling factor -- just multiply the result
of the get() operations by the scale factor.

The coordinates given to be moved to are those of where the center of the pie
should go.

Subject: how to relocate the pie chart on a figure?

From: Amy Wang

Date: 25 Sep, 2008 14:10:03

Message: 12 of 15

Wow!!! Thanks a lot!!!!
The pie charts did move to where we want them!

However, the colors of the pie chart seems to appear in gray scale since the image is in gray scale. Is it possible to use gray scale for the image and then another colormap for the pie charts?
And we don't need the text of the pie charts.

Thank you for your time!!

Walter Roberson <roberson@hushmail.com> wrote in message <pjwCk.32537$rV4.22054@newsfe03.iad>...
> Amy Wang wrote:
> > we would like to draw more than one pie chart over our image (say "R" for example
> > on my previous message). Therefore it would be easier if we know how to move the
> > pie chart.
>
> > You mentioned "adjust the Vertices property of the patch, adding the constant
> > x and y shifts to each row", can you explain a bit more?
>
> e.g.,
>
> Piehandles = movepieto( pie(DataToPlot), Newx, Newy );
>
> function piehandles = movepieto( piehandles, newx, newy );
> %assume pairs, patch first then text
> for K = 1:2:length(piehandles)
> set(piehandles(K), 'Vertices', ...
> bsxfun(@plus, get(piehandles(K), 'Vertices'), [newx newy]) );
> set(piehandles(K+1), 'Position', get(piehandles(K+1),'Position') + [newx, newy, 0]);
> end
> end
>
>
> Note that this only does linear shifts of the pie chart and does not resize it.
> It would be trivial to add a scaling factor -- just multiply the result
> of the get() operations by the scale factor.
>
> The coordinates given to be moved to are those of where the center of the pie
> should go.

Subject: how to relocate the pie chart on a figure?

From: Amy Wang

Date: 25 Sep, 2008 14:23:01

Message: 13 of 15

I used freezecolors.m provided by john and the problem is solved. I have two colormaps.
but my pie chart is pie([2 8]), it shows the same color on the figure for both 20% and 80%.
How can I change the patch face color that is related to my values? Because I would like to deal with all the pie charts at the same time not by clicking and changing one by one.

Thank you!!!


"Amy Wang" <amy.wang@ua.ac.be> wrote in message <gbg63r$q34$1@fred.mathworks.com>...
> Wow!!! Thanks a lot!!!!
> The pie charts did move to where we want them!
>
> However, the colors of the pie chart seems to appear in gray scale since the image is in gray scale. Is it possible to use gray scale for the image and then another colormap for the pie charts?
> And we don't need the text of the pie charts.
>
> Thank you for your time!!
>
> Walter Roberson <roberson@hushmail.com> wrote in message <pjwCk.32537$rV4.22054@newsfe03.iad>...
> > Amy Wang wrote:
> > > we would like to draw more than one pie chart over our image (say "R" for example
> > > on my previous message). Therefore it would be easier if we know how to move the
> > > pie chart.
> >
> > > You mentioned "adjust the Vertices property of the patch, adding the constant
> > > x and y shifts to each row", can you explain a bit more?
> >
> > e.g.,
> >
> > Piehandles = movepieto( pie(DataToPlot), Newx, Newy );
> >
> > function piehandles = movepieto( piehandles, newx, newy );
> > %assume pairs, patch first then text
> > for K = 1:2:length(piehandles)
> > set(piehandles(K), 'Vertices', ...
> > bsxfun(@plus, get(piehandles(K), 'Vertices'), [newx newy]) );
> > set(piehandles(K+1), 'Position', get(piehandles(K+1),'Position') + [newx, newy, 0]);
> > end
> > end
> >
> >
> > Note that this only does linear shifts of the pie chart and does not resize it.
> > It would be trivial to add a scaling factor -- just multiply the result
> > of the get() operations by the scale factor.
> >
> > The coordinates given to be moved to are those of where the center of the pie
> > should go.

Subject: how to relocate the pie chart on a figure?

From: Amy Wang

Date: 25 Sep, 2008 15:07:02

Message: 14 of 15

Problem solved!
Thanks!!!

"Amy Wang" <amy.wang@ua.ac.be> wrote in message <gbg6s5$8bg$1@fred.mathworks.com>...
> I used freezecolors.m provided by john and the problem is solved. I have two colormaps.
> but my pie chart is pie([2 8]), it shows the same color on the figure for both 20% and 80%.
> How can I change the patch face color that is related to my values? Because I would like to deal with all the pie charts at the same time not by clicking and changing one by one.
>
> Thank you!!!
>
>
> "Amy Wang" <amy.wang@ua.ac.be> wrote in message <gbg63r$q34$1@fred.mathworks.com>...
> > Wow!!! Thanks a lot!!!!
> > The pie charts did move to where we want them!
> >
> > However, the colors of the pie chart seems to appear in gray scale since the image is in gray scale. Is it possible to use gray scale for the image and then another colormap for the pie charts?
> > And we don't need the text of the pie charts.
> >
> > Thank you for your time!!
> >
> > Walter Roberson <roberson@hushmail.com> wrote in message <pjwCk.32537$rV4.22054@newsfe03.iad>...
> > > Amy Wang wrote:
> > > > we would like to draw more than one pie chart over our image (say "R" for example
> > > > on my previous message). Therefore it would be easier if we know how to move the
> > > > pie chart.
> > >
> > > > You mentioned "adjust the Vertices property of the patch, adding the constant
> > > > x and y shifts to each row", can you explain a bit more?
> > >
> > > e.g.,
> > >
> > > Piehandles = movepieto( pie(DataToPlot), Newx, Newy );
> > >
> > > function piehandles = movepieto( piehandles, newx, newy );
> > > %assume pairs, patch first then text
> > > for K = 1:2:length(piehandles)
> > > set(piehandles(K), 'Vertices', ...
> > > bsxfun(@plus, get(piehandles(K), 'Vertices'), [newx newy]) );
> > > set(piehandles(K+1), 'Position', get(piehandles(K+1),'Position') + [newx, newy, 0]);
> > > end
> > > end
> > >
> > >
> > > Note that this only does linear shifts of the pie chart and does not resize it.
> > > It would be trivial to add a scaling factor -- just multiply the result
> > > of the get() operations by the scale factor.
> > >
> > > The coordinates given to be moved to are those of where the center of the pie
> > > should go.

Subject: how to relocate the pie chart on a figure?

From: Bing Yang

Date: 4 Jun, 2013 12:23:09

Message: 15 of 15

Excuse me ! I met the same question with you. I could move the positon of the pie but the color of it is same . How did you solve this problem?

Thanks in advance!

Tags for 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