[Tex/LaTex] grouping options problem in `pgfplots.groupplots` when also using `units` library

pgfplotstikz-pgf

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?

Best Answer

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