help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Stacked bar plot legend reversed


From: Shaun Jackman
Subject: Re: Stacked bar plot legend reversed
Date: Wed, 4 Jan 2012 17:29:05 -0800

On Wed, 2012-01-04 at 17:22 -0800, Ben Abbott wrote:
> On Jan 4, 2012, at 3:45 PM, Shaun Jackman wrote:
> 
> > Hi,
> > 
> > When drawing a stacked bar plot with a legend, the data is drawn from
> > bottom to top, whereas the legend is drawn from top to bottom, which
> > isn't exactly intuitive. Is there any way to reverse the order of the
> > legend?
> > 
> > For example, the following snippet draws the Oranges data stacked on top
> > of Apples, but the legend will read from top to bottom Apples and then
> > Oranges:
> > 
> > h = [1 2; 3 4]
> > bar(h, 'stacked')
> > legend('Apples', 'Oranges')
> > 
> > Thanks,
> > Shaun
> 
> Flipping the order of the axes children will have the effect you want.
> 
>       h = [1 2; 3 4]
>       bar(h, 'stacked')
>       legend('Apples', 'Oranges', 'location', 'northwest')
>       set (gca, 'children', flipud (get (gca, 'children')))
> 
> Ben

Hi Ben,

Thanks for the suggestion. With Octave 3.2.3, I get the following error
message:

octave:1> h = [1 2; 3 4];
octave:2> bar(h, 'stacked')
octave:3> legend('Apples', 'Oranges', 'location', 'northwest')
octave:4> set (gca, 'children', flipud (get (gca, 'children')))
error: set: new children must be a permutation of existing children

Cheers,
Shaun




reply via email to

[Prev in Thread] Current Thread [Next in Thread]