2

For some reason, groupplot y labels seem to be very reluctant to styling. How can I

  • rotate the ylabels,
  • shift them a little bit closer to the tick labels, and
  • have a multi-line label

in the following example? I have tried what feels like a 1,000 different ways of specifying the y label style, and none worked.

In particular, the following MWE does not work and yields this:

enter image description here

\documentclass{article}

\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{pgfplots.groupplots}
\pgfplotsset{compat=1.16}

\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{groupplot}[
    group style={
        group size=1 by 2,
        xlabels at=edge bottom,
        xticklabels at=edge bottom,
        vertical sep=0pt
    },
    width=8cm,
    height=3.5cm,
    xlabel={Time (s)},
    xmin=0, xmax=7,
    tickpos=left
]
\nextgroupplot[ymin=-1.5, ymax=1.5, ylabel={$\sin(x)$}, y label/.style={rotate=-90, xshift=.5cm}]
\addplot[domain=0:7] {sin(deg(x))};
\nextgroupplot[ymin=-1.5, ymax=1.5, ylabel={$\cos(x)$}]
\addplot[domain=0:7] {cos(deg(x))};
\end{groupplot}
\end{tikzpicture}
\end{figure}
\end{document}
3
  • 1
    Use every axis y label/.style={rotate=-90, xshift=.5cm} instead (and adjust the parameters to your needs). To have multiline, use e.g. align=center.
    – user121799
    Commented Feb 5, 2019 at 19:14
  • @marmot Hah, now I feel stupid. What do I need the "every axis" part for, exactly? If I have a normal axis environment, I can also do this without it, can't I? And, uhh - should I delete the question?
    – Eike P.
    Commented Feb 5, 2019 at 19:21
  • 1
    I do not think it is a stupid question. I leave the decision whether or not to delete it up to you. every axis seems to suggest it applies to every axis but the effect is local, and it is used e.g. on p. 246 of the manual. At least from what I see it seems to behave like a local option if passed to an axis, but you could insert it globally with \pgfplotsset, if you want.
    – user121799
    Commented Feb 5, 2019 at 19:25

1 Answer 1

2

Here is a way that works, I think. (I didn't find y label/.style in the manual, so it might mean it doesn't exist and thus does not have an impact. If you use every axis y label/.style inside the argument of an axis or a group plot, its effect will still be local.)

\documentclass{article}

\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{pgfplots.groupplots}
\pgfplotsset{compat=1.16}

\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{groupplot}[
    group style={
        group size=1 by 2,
        xlabels at=edge bottom,
        xticklabels at=edge bottom,
        vertical sep=0pt
    },
    width=8cm,
    height=3.5cm,
    xlabel={Time (s)},
    xmin=0, xmax=7,
    tickpos=left
]
\nextgroupplot[ymin=-1.5, ymax=1.5, ylabel={$\sin(x)$\\ don't despair!}, 
 every axis y label/.style={
            at={(ticklabel cs:0.5)},rotate=-90,anchor=center,align=center
        }]
\addplot[domain=0:7] {sin(deg(x))};
\nextgroupplot[ymin=-1.5, ymax=1.5, ylabel={$\cos(x)$}]
\addplot[domain=0:7] {cos(deg(x))};
\end{groupplot}
\end{tikzpicture}
\end{figure}
\end{document}

enter image description here

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .