1

Similar to this question I want to align my y labels of groupplots. The style

ylabel absolute, y label/.append style={yshift=0em},

does the trick, and thus I want to apply this to every group plot. However, I don't really understand the settings category thing that's going on in tikz/pgfplots. I've tried many variations of the code below, which all compiled fine, but had no effect. Could someone point out how I can adress each group plot and append the above line to the style? *And maybe point out how to do this in general (where to find the subcategories etc)?

Basically, what I try to achieve is a way to modify the style of each group (groupplot?) and append the above ylabel absolute positioning. So something like every axis/ylabel, but for groups. (The former doesn't work, since it misplaces the ylabel of 3D plots.)

Minimal not-working example:

\documentclass{article}
\pgfplotsset{compat=newest}
\usepackage{pgfplots}
\usetikzlibrary{pgfplots.groupplots} % needs to be loaded exactly like this
\pgfplotsset{ /pgfplots/group/.append style = {
    ylabel absolute, y label/.append style={yshift=0em},
  }
}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[
    group style={
     group name=my plots,
        group size=1 by 2,
        xlabels at=edge bottom,
        ylabels at=edge left
    },height=4cm, width=4cm]
\nextgroupplot[ylabel={foo},]
\addplot coordinates {(0,0) (-0.1,-0.1) (-0.2,-0.2)};
\nextgroupplot[ylabel={bar},]
\addplot coordinates {(0,2) (1,1) (2,0)};
\end{groupplot}
\end{tikzpicture}
\end{document}
mike
  • 333
  • 1
  • 3
  • 13
  • 2
    It would be really nice if you added a complete example as well, so that we don't have to set up everything ourselves to test. – Torbjørn T. May 14 '16 at 09:02
  • When adding a \documentclass and document environment your code produced aligned ylabels regardless of whether those styles are included or not. Do you have a compat setting in your code? – Torbjørn T. May 14 '16 at 10:08

1 Answers1

1

Looking at the code of the groupplots library, I see that the style /pgfplots/group/every plot is added to each \nextgroupplot. So to only affect axes in groupplots environments, append to that style, e.g.

\pgfplotsset{/pgfplots/group/every plot/.append style = {
    ylabel absolute, y label/.append style={yshift=0em},
  }
}

enter image description here

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}
\usepgfplotslibrary{groupplots} 
\pgfplotsset{/pgfplots/group/every plot/.append style = {
    ylabel absolute, y label/.append style={yshift=0em},
  }
}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[
    group style={
     group name=my plots,
        group size=1 by 2,
        xlabels at=edge bottom,
        ylabels at=edge left
    },height=4cm, width=4cm]
\nextgroupplot[ylabel={foo}]
\addplot coordinates {(0,0) (-0.1,-0.1) (-0.2,-0.2)};
\nextgroupplot[ylabel={bar}]
\addplot coordinates {(0,2) (1,1) (2,0)};
\end{groupplot}
\end{tikzpicture}

\begin{tikzpicture}
\begin{axis}[ylabel=abc]
\addplot3 coordinates {(0,0,0)(1,1,1)};
\end{axis}
\end{tikzpicture}
\end{document}
Torbjørn T.
  • 206,688
  • It would but sadly this affects the second axes of all 3D plots aswell (they are in some axes too^^). So the y-label for those jumps arround to the place, where the x label should be. I'll refine my statement of what I want to achieve. – mike May 14 '16 at 18:38
  • @mike Was that better? – Torbjørn T. May 14 '16 at 18:56
  • Thank you, that is exactly what I needed. Could you enlighten me, where/how you found out, that it's 'pgfplots/group/every plot/'? – mike May 15 '16 at 07:58
  • @mike Well, I took the complicated route, and looked at the code of the groupplots library, and tried to find where a new axis was added to the group. But I see that it is mentioned in the manual as well, where it says that it is equivalent to adding options to the groupplot environment. – Torbjørn T. May 15 '16 at 08:20
  • Thanks! Now I'm really satisfied. However, the directory scheme is really strange: as you showed me you need group/every plot/.append style for the general settings of every group, but just e.g. group/vertical sep=2cm to change the group specific options. Anyway, thanks again! – mike May 15 '16 at 09:57