Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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
add comment

1 Answer

up vote 4 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.units.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
add comment

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.