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: Ben Abbott
Subject: Re: Stacked bar plot legend reversed
Date: Wed, 04 Jan 2012 20:22:21 -0500

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


reply via email to

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