Pgfplots: Legend in stacked bar chart

View: New views
2 Messages — Rating Filter:   Alert me  

Pgfplots: Legend in stacked bar chart

by Rob Basten :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I am using a stacked bar chart (ybar). Each plot that I add is put on top of
the previous plots (bottom-up), which I expected. However, the legend is
constructed top-down. As a result, the top part of the stacked bars, is at
the bottom of the legend, and the bottom part of the stacked bars, is at the
top of the legend. Is it possible to reverse the order of the entries in the
legend?

Thanks,
Rob


------------------------------------------------------------------------------
_______________________________________________
pgf-users mailing list
pgf-users@...
https://lists.sourceforge.net/lists/listinfo/pgf-users

Parent Message unknown Re: Pgfplots: Legend in stacked bar chart

by Christian Feuersaenger :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello Rob,

the developerversion of pgfplots now has a 'reverse legend' feature
which does exactly what you want.

This feature has been suggested and implemented by Tom Cashman (thanks,
Tom!).

Until the next version is ready, you can download the (not completely
stable) developerversion or you can use the attached self-contained
implementation of Tom Cashman which can be used as last statement in an
axis.

Please note that this implementation should be considered as
non-supported special feature which will probably cease to work in one
of the following stable versions of pgfplots (without notice)! Use at
your own risk!

Regards

Christian

--
Christian Feuersaenger
Institut fuer Numerische Simulation
Rheinische Friedrich-Wilhelms Universitaet Bonn
Wegelerstrasse 6
D-53115 Bonn
Germany

Tel:  +49 228 733848
URL:  http://wissrech.ins.uni-bonn.de/people/feuersaenger.html

% Please note that this implementation should be considered as non-supported special feature which will probably cease to work in one of the following stable versions of pgfplots (without notice)! Use at your own risk!

\newcommand{\reverselegend}{%
  % Reverse \pgfplots@plotspeclist
  \pgfplotslistnewempty\pgfplots@plotspeclist@reversed
  \begingroup
    \pgfplotslistforeachungrouped\pgfplots@plotspeclist\as\pgfplots@plotspeclisttmp{%
      \expandafter\pgfplotslistpushfront\pgfplots@plotspeclisttmp\to\pgfplots@plotspeclist@reversed
    }%
    \global\let\pgfplots@plotspeclist=\pgfplots@plotspeclist@reversed
    \global\let\pgfplots@plotspeclist@reversed=\relax
  \endgroup

  % Reverse \pgfplots@legend
  \pgfplotslistnewempty\pgfplots@legend@reversed
  \begingroup
    \pgfplotslistforeachungrouped\pgfplots@legend\as\pgfplots@legendtmp{%
      \expandafter\pgfplotslistpushfront\pgfplots@legendtmp\to\pgfplots@legend@reversed
    }%
    \global\let\pgfplots@legend=\pgfplots@legend@reversed
    \global\let\pgfplots@legend@reversed=\relax
  \endgroup
}

------------------------------------------------------------------------------

_______________________________________________
pgf-users mailing list
pgf-users@...
https://lists.sourceforge.net/lists/listinfo/pgf-users