[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Stacked bar plot legend reversed
From: |
Ben Abbott |
Subject: |
Re: Stacked bar plot legend reversed |
Date: |
Wed, 04 Jan 2012 20:39:48 -0500 |
On Jan 4, 2012, at 8:29 PM, Shaun Jackman wrote:
> 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
Shaun,
It appears you've found a bug in 3.2.3.
Upgrading to a newer version of Octave should solve your problem.
We're about the release version 3.6.0. Since 3.2.3, we've released 3.2,4,
3.4.0, 3.4.1, 3.4.2, and 3.4.3.
There may be a way to work around the bug, but I don't have a 3.2.x version to
experiment with.
Ben