TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a problem with the grouping options of pgfplots.groupplots. Besides the labels I have also units defined. With the option xlabels at=edge bottom only the label, but not the unit is moved to the bottom of the group (same with ylabels).

\pgfplotsset{
    use units,
    x unit=s, x unit prefix={}, % 5.3.1 p227
    y unit=\unitfrac{rad}{s}, y unit prefix={},
    xlabel=time,
    ylabel=frequency $\omega$,
}

\begin{groupplot}[
    group style={
     group name=my plots,
        group size=2 by 2,
        xlabels at=edge bottom,
        ylabels at=edge left,
    },

Any ideas how to put also the unit to the bottom?

share|improve this question
up vote 10 down vote accepted

Edit: Simple solution: If you just need to get this working and don't want to fiddle with the library code, you can just switch off the units for individual plots by using \nextgroupplot [x unit={}] or y unit={} or both, depending on which plot is next.

"Proper" Solution: It seems like these two libraries are just not aware of each other, so you'll have to make some adjustments to the groupplots code. The labels are set right in the main chunk of code, unfortunately, so you can't get away with just redefining some small macros.

In the file tikzlibrarypgfplots.groupplots.code.tex you have to replace the two occurrences of the line

\pgfplots@glob@TMPa,/pgfplots/group/plot c\pgfplots@column r\pgfplots@row/.append style={/pgfplots/xlabel={}}}%

with

\pgfplots@glob@TMPa,/pgfplots/group/plot c\pgfplots@column r\pgfplots@row/.append style={/pgfplots/xlabel={}}%
\ifpgfplots@units@use
  \pgfplots@glob@TMPa,/pgfplots/group/plot c\pgfplots@column r\pgfplots@row/.append style={/pgfplots/x unit={}}
\fi}%

and the two occurrences of the line

\pgfplots@glob@TMPa,/pgfplots/group/plot c\pgfplots@column r\pgfplots@row/.append style={/pgfplots/ylabel={}}}%

with

\pgfplots@glob@TMPa,/pgfplots/group/plot c\pgfplots@column r\pgfplots@row/.append style={/pgfplots/ylabel={}}%
\ifpgfplots@units@use
  \pgfplots@glob@TMPa,/pgfplots/group/plot c\pgfplots@column r\pgfplots@row/.append style={/pgfplots/y unit={}}
\fi}%

This will work with or without the units library, and with all combinations of edge bottom, edge top, edge left, and edge right.

Here's an example of the behaviour of the modified library:

\documentclass{minimal}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots,units}

\begin{document}
\begin{tikzpicture}

\pgfplotsset{
    use units,
    x unit=s, x unit prefix={}, % 5.3.1 p227
    y unit=m, y unit prefix=k,
    xlabel=time,
    ylabel=frequency $\omega$,
}

\begin{groupplot}[
    group style={
     group name=my plots,
        group size=2 by 2,
        xlabels at=edge bottom,
        ylabels at=edge left
    },height=4cm, width=4cm]
\nextgroupplot
\addplot coordinates {(0,0) (1,1) (2,2)};
\nextgroupplot
\addplot coordinates {(0,2) (1,1) (2,0)};
\nextgroupplot
\addplot coordinates {(0,2) (1,1) (2,1)};
\nextgroupplot
\addplot coordinates {(0,2) (1,1) (1,0)};
\end{groupplot}

\end{tikzpicture}
\end{document}

pgfplots with units and patched groupplots library

share|improve this answer
    
if you use the units also for scaling i thing the first 'simple' workaround doesn't help (then you could also ignore units and put the unit in math mode into your label). the 'proper' solution works fine although i hoped it would be easier. but thanks! – kromuchi Mar 26 '11 at 18:07
    
thanks for the hack! Could this be patched into the pgfplots package? – riddleculous Apr 3 at 21:05
1  
@riddleculous: Sorry, there was an error in my answer, the correct file name is tikzlibrarypgfplots.groupplots.code.tex. For getting this incorporated into PGFPlots, you could open a feature request – Jake Apr 3 at 21:24
1  
This is not a feature request but a bug which was already reported here. As always: Jake is the best fixing the bugs ;) I'll edit the report to point to this fix. Many thanks for that! – Stefan Pinnow Apr 3 at 21:41
1  
Thanks for the reports and thanks for the fix! It is now part of pgfplots (will become part of pgfplots 1.14). – Christian Feuersänger Apr 17 at 13:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.