3

I'd like to have the tick label for the y-axis only printed once in a groupplot. This would be very useful for the case when one uses the following options:

ylabels at=edge left,
yticklabels at=edge left,

Is this possible?

Picture

enter image description here

MWE

\documentclass[
a4paper
]{scrartcl}

\usepackage{
amsmath,
tikz,
pgfplots,
}

\usepgfplotslibrary{
groupplots,
}

\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}


\begin{document}
\begin{center}
\begin{tikzpicture}[font=\small]
\begin{groupplot}[
group style={
    group size=4 by 4, %4 column(s), 4 row(s)
    horizontal sep=0cm,
    vertical sep=1.5cm,
    ylabels at=edge left,
    yticklabels at=edge left,
},
xlabel={Bla},
ylabel={Process},
%
every x tick scale label/.append style={
    at={(0.95,0)},yshift=-1.5em,anchor=north,inner sep=0pt
},
every y tick scale label/.append style={
    at={(-0.05,0.99)},anchor=east,inner sep=0pt
},
scale ticks above exponent={2}
]
\nextgroupplot
\addplot[only marks] coordinates{(1,1200) (3,500)};
\nextgroupplot
\addplot[only marks] coordinates{(2,1200) (4,400)};
\end{groupplot}
\end{tikzpicture}
\end{center}
\end{document}

closed as off-topic by Stefan Pinnow, Henri Menke, Schweinebacke, Maarten Dhondt, TeXnician Jun 26 '17 at 5:59

  • This question does not fall within the scope of TeX, LaTeX or related typesetting systems as defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Is it (not) that simple or has it really been overlooked? :( Whether the label's position is adjusted or not, it looks quite awful when plots are grouped together like this. :( – henry Sep 11 '14 at 6:42
  • 4
    I'm voting to close this question because this was a bug which is solved in PGFPlots v1.15 – Stefan Pinnow Jun 26 '17 at 4:38
4

This seems like an oversight in the groupplots library. The necessary change to fix this behaviour isn't complicated (it's just a single line), but it affects a very long internal macro.

To fix the library, put the following code in your preamble:

\makeatletter
%
% Determine the ticklabels of both x and y.
%
\def\pgfplots@group@determine@ticklabels{%
    \def\pgfplots@loc@TMPa{all}
    \def\pgfplots@loc@TMPb{top}
    \def\pgfplots@loc@TMPc{lower}
    \ifx\pgfplots@loc@TMPa\pgfplots@group@xticklabels%
      % Do nothing as all should have xticklabels
    \fi
    \gdef\pgfplots@glob@TMPa{}
    \ifx\pgfplots@loc@TMPb\pgfplots@group@xticklabels%
      \foreach \pgfplots@column in {1,...,\pgfplots@group@columns} {%
          \expandafter\xdef\expandafter\pgfplots@glob@TMPa\expandafter{%
              \pgfplots@glob@TMPa,/pgfplots/group/plot c\pgfplots@column r1/.append style={xticklabel pos=upper}}%
          \ifnum1<\pgfplots@group@rows\relax
            \foreach \pgfplots@row in {2,...,\pgfplots@group@rows} {%
                \expandafter\xdef\expandafter\pgfplots@glob@TMPa\expandafter{%
                    \pgfplots@glob@TMPa,/pgfplots/group/plot c\pgfplots@column r\pgfplots@row/.append style={/pgfplots/xticklabels={}}}%
            }%
          \fi%
      }%
    \fi
    \ifx\pgfplots@loc@TMPc\pgfplots@group@xticklabels%
      \foreach \pgfplots@column in {1,...,\pgfplots@group@columns} {%
          \expandafter\xdef\expandafter\pgfplots@glob@TMPa\expandafter{%
              \pgfplots@glob@TMPa,/pgfplots/group/plot c\pgfplots@column r\pgfplots@group@rows/.append style={xticklabel pos=lower}}%
          \ifnum1<\pgfplots@group@rows\relax
            \pgfplotsgroupplotsmath@decrease\pgfplots@group@rows
            \foreach \pgfplots@row in {1,...,\pgfmathresult} {%
                \expandafter\xdef\expandafter\pgfplots@glob@TMPa\expandafter{%
                    \pgfplots@glob@TMPa,/pgfplots/group/plot c\pgfplots@column r\pgfplots@row/.append style={/pgfplots/xticklabels={}}}%
            }%
          \fi%
      }%
    \fi%
    % 
    % Defining styles for the ytick's
    % 
    \def\pgfplots@loc@TMPb{left}
    \def\pgfplots@loc@TMPc{right}
    \ifx\pgfplots@loc@TMPa\pgfplots@group@yticklabels%
      % Do nothing as all should have yticklabels
    \fi
    \ifx\pgfplots@loc@TMPb\pgfplots@group@yticklabels%
      \foreach \pgfplots@row in {1,...,\pgfplots@group@rows} {%
          \expandafter\xdef\expandafter\pgfplots@glob@TMPa\expandafter{%
              \pgfplots@glob@TMPa,/pgfplots/group/plot c1r\pgfplots@row/.append style={yticklabel pos=left}}%
          \ifnum1<\pgfplots@group@columns\relax
            \foreach \pgfplots@column in {2,...,\pgfplots@group@columns} {%
                \expandafter\xdef\expandafter\pgfplots@glob@TMPa\expandafter{%
                    \pgfplots@glob@TMPa,/pgfplots/group/plot c\pgfplots@column r\pgfplots@row/.append style={/pgfplots/yticklabels={}, /pgfplots/ytick scale label code/.code={}}}%
            }%
          \fi%
      }%
    \fi
    \ifx\pgfplots@loc@TMPc\pgfplots@group@yticklabels%
      \foreach \pgfplots@row in {1,...,\pgfplots@group@rows} {%
          \expandafter\xdef\expandafter\pgfplots@glob@TMPa\expandafter{%
              \pgfplots@glob@TMPa,/pgfplots/group/plot c\pgfplots@group@columns r\pgfplots@row/.append style={yticklabel pos=right}}%
          \ifnum1<\pgfplots@group@columns\relax
            \pgfplotsgroupplotsmath@decrease\pgfplots@group@columns
            \foreach \pgfplots@column in {1,...,\pgfmathresult} {%
                \expandafter\xdef\expandafter\pgfplots@glob@TMPa\expandafter{%
                    \pgfplots@glob@TMPa,/pgfplots/group/plot c\pgfplots@column r\pgfplots@row/.append style={/pgfplots/yticklabels={}, /pgfplots/ytick scale label code/.code={}}}%
            }%
          \fi%
      }%
    \fi%
    \expandafter\pgfkeys\expandafter{\pgfplots@glob@TMPa}
}
\makeatother

\documentclass{article}

\usepackage{pgfplots}

\usepgfplotslibrary{groupplots}

\makeatletter
%
% Determine the ticklabels of both x and y.
%
\def\pgfplots@group@determine@ticklabels{%
    \def\pgfplots@loc@TMPa{all}
    \def\pgfplots@loc@TMPb{top}
    \def\pgfplots@loc@TMPc{lower}
    \ifx\pgfplots@loc@TMPa\pgfplots@group@xticklabels%
      % Do nothing as all should have xticklabels
    \fi
    \gdef\pgfplots@glob@TMPa{}
    \ifx\pgfplots@loc@TMPb\pgfplots@group@xticklabels%
      \foreach \pgfplots@column in {1,...,\pgfplots@group@columns} {%
          \expandafter\xdef\expandafter\pgfplots@glob@TMPa\expandafter{%
              \pgfplots@glob@TMPa,/pgfplots/group/plot c\pgfplots@column r1/.append style={xticklabel pos=upper}}%
          \ifnum1<\pgfplots@group@rows\relax
            \foreach \pgfplots@row in {2,...,\pgfplots@group@rows} {%
                \expandafter\xdef\expandafter\pgfplots@glob@TMPa\expandafter{%
                    \pgfplots@glob@TMPa,/pgfplots/group/plot c\pgfplots@column r\pgfplots@row/.append style={/pgfplots/xticklabels={}}}%
            }%
          \fi%
      }%
    \fi
    \ifx\pgfplots@loc@TMPc\pgfplots@group@xticklabels%
      \foreach \pgfplots@column in {1,...,\pgfplots@group@columns} {%
          \expandafter\xdef\expandafter\pgfplots@glob@TMPa\expandafter{%
              \pgfplots@glob@TMPa,/pgfplots/group/plot c\pgfplots@column r\pgfplots@group@rows/.append style={xticklabel pos=lower}}%
          \ifnum1<\pgfplots@group@rows\relax
            \pgfplotsgroupplotsmath@decrease\pgfplots@group@rows
            \foreach \pgfplots@row in {1,...,\pgfmathresult} {%
                \expandafter\xdef\expandafter\pgfplots@glob@TMPa\expandafter{%
                    \pgfplots@glob@TMPa,/pgfplots/group/plot c\pgfplots@column r\pgfplots@row/.append style={/pgfplots/xticklabels={}}}%
            }%
          \fi%
      }%
    \fi%
    % 
    % Defining styles for the ytick's
    % 
    \def\pgfplots@loc@TMPb{left}
    \def\pgfplots@loc@TMPc{right}
    \ifx\pgfplots@loc@TMPa\pgfplots@group@yticklabels%
      % Do nothing as all should have yticklabels
    \fi
    \ifx\pgfplots@loc@TMPb\pgfplots@group@yticklabels%
      \foreach \pgfplots@row in {1,...,\pgfplots@group@rows} {%
          \expandafter\xdef\expandafter\pgfplots@glob@TMPa\expandafter{%
              \pgfplots@glob@TMPa,/pgfplots/group/plot c1r\pgfplots@row/.append style={yticklabel pos=left}}%
          \ifnum1<\pgfplots@group@columns\relax
            \foreach \pgfplots@column in {2,...,\pgfplots@group@columns} {%
                \expandafter\xdef\expandafter\pgfplots@glob@TMPa\expandafter{%
                    \pgfplots@glob@TMPa,/pgfplots/group/plot c\pgfplots@column r\pgfplots@row/.append style={/pgfplots/yticklabels={}, /pgfplots/ytick scale label code/.code={}}}%
            }%
          \fi%
      }%
    \fi
    \ifx\pgfplots@loc@TMPc\pgfplots@group@yticklabels%
      \foreach \pgfplots@row in {1,...,\pgfplots@group@rows} {%
          \expandafter\xdef\expandafter\pgfplots@glob@TMPa\expandafter{%
              \pgfplots@glob@TMPa,/pgfplots/group/plot c\pgfplots@group@columns r\pgfplots@row/.append style={yticklabel pos=right}}%
          \ifnum1<\pgfplots@group@columns\relax
            \pgfplotsgroupplotsmath@decrease\pgfplots@group@columns
            \foreach \pgfplots@column in {1,...,\pgfmathresult} {%
                \expandafter\xdef\expandafter\pgfplots@glob@TMPa\expandafter{%
                    \pgfplots@glob@TMPa,/pgfplots/group/plot c\pgfplots@column r\pgfplots@row/.append style={/pgfplots/yticklabels={}, /pgfplots/ytick scale label code/.code={}}}%
            }%
          \fi%
      }%
    \fi%
    \expandafter\pgfkeys\expandafter{\pgfplots@glob@TMPa}
}
\makeatother

\begin{document}
\begin{center}
\begin{tikzpicture}[font=\small]
\begin{groupplot}[
group style={
    group size=2 by 1, %4 column(s), 4 row(s)
    horizontal sep=0cm,
    vertical sep=1.5cm,
    ylabels at=edge left,
    yticklabels at=edge left,
},
xlabel={Bla},
ylabel={Process},
%
every x tick scale label/.append style={
    at={(0.95,0)},yshift=-1.5em,anchor=north,inner sep=0pt
},
every y tick scale label/.append style={
    at={(-0.05,0.99)},anchor=east,inner sep=0pt
},
scale ticks above exponent={2}
]
\nextgroupplot
\addplot[only marks] coordinates{(1,1200) (3,500)};
\nextgroupplot
\addplot[only marks] coordinates{(2,1200) (4,400)};
\end{groupplot}
\end{tikzpicture}
\end{center}
\end{document}
1

Only as a workaround: You can set the the scaled y ticks=true option for the left plot manually:

\documentclass{scrartcl}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\usepgfplotslibrary{groupplots}
\begin{document}
\begin{center}
\begin{tikzpicture}[font=\small]
\begin{groupplot}[
  group style={
    group size=4 by 4, %4 column(s), 4 row(s)% 
    horizontal sep=0cm,
    vertical sep=1.5cm,
    ylabels at=edge left,
    yticklabels at=edge left,
  },
  xlabel={Bla},
  ylabel={Process},
  %
  x tick scale label style={
    at={(0.95,0)},yshift=-1.5em,anchor=north,inner sep=0pt
  },
  y tick scale label style={
    at={(-0.05,0.99)},anchor=east,inner sep=0pt,
  },
  scale ticks above exponent={2},
  scaled y ticks=false% <-
]
\nextgroupplot[scaled y ticks=true]% <-
\addplot[only marks] coordinates{(1,1200) (3,500)};
\nextgroupplot
\addplot[only marks] coordinates{(2,1200) (4,400)};
\end{groupplot}
\end{tikzpicture}
\end{center}
\end{document}

enter image description here

But there are additional problems in the groupplot: The tick position of the left and the right plot are different. The groupplot is wider then the \linewidth. There is not enough space for a 4x4 groupplot on the page. In addition I would insert a small horizontal sep between the two plots.

\documentclass{scrartcl}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\usepgfplotslibrary{groupplots}

\begin{document}
\begin{center}
\begin{tikzpicture}[font=\small]
\begin{groupplot}[
  group style={
    group size=2 by 2, %2 column(s), 2 row(s)% <-
    horizontal sep=5pt,
    vertical sep=1.5cm,
    ylabels at=edge left,
    yticklabels at=edge left,
  },
  width=.55\linewidth,% <-
  xlabel={Bla},
  ylabel={Process},
  %
  x tick scale label style={
    at={(0.95,0)},yshift=-1.5em,anchor=north,inner sep=0pt
  },
  y tick scale label style={
    at={(-0.05,0.99)},anchor=east,inner sep=0pt,
  },
  ymin=400,ymax=1200,enlarge y limits=.1,% <-
  scale ticks above exponent={2},
  scaled y ticks=false% <-
]
\nextgroupplot[scaled y ticks=true]% <-
\addplot[only marks] coordinates{(1,1200) (3,500)};
\nextgroupplot
\addplot[only marks] coordinates{(2,1200) (4,400)};
\end{groupplot}
\end{tikzpicture}
\end{center}
\end{document}

enter image description here

  • Oh, these little details I overlooked sorry. Yeah the code was produced for the MWE only. Interesting bit about specifying the width that way. – henry Sep 11 '14 at 9:09
  • In some cases, I need scaling for the x ticks though and this workaround will break. I'll edit the op in 5 minutes. – henry Sep 11 '14 at 9:46
  • Um... never mind. Little error on my part, looked the wrong row in my actual, big groupplot. – henry Sep 11 '14 at 9:48

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