3

I tried to use groupplots to arrange several bar plots but the titles are drawn on top of the axis labels of the plot above. Am I doing something wrong here?

\documentclass{article}

\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}

\begin{document}
  \begin{tikzpicture}
    \begin{groupplot}[group style={group size=2 by 2},width=0.45\textwidth,ybar]
      \nextgroupplot[title=title 1-1]
        \addplot coordinates { (1,1) (42,23)};
      \nextgroupplot[title=title 1-2]
        \addplot coordinates { (1,1) (42,23)};
      \nextgroupplot[title=title 2-1]
        \addplot coordinates { (1,1) (42,23)};
      \nextgroupplot[title=title 2-2]
        \addplot coordinates { (1,1) (42,23)};
    \end{groupplot}
  \end{tikzpicture}
\end{document}

Titles of sub plots

Edit: maybe I should also mention why I'm specifically asking for ybar plots. I tried the same example without the ybar and the spacing was different. The title fits below the axis label without this option but the spacing still looked off. Anyway, I need bar plots so I cannot remove this option.

4

Use the vertical sep=<length> option to increase the vertical spacing:

\documentclass{article}

\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}

\begin{document}
  \begin{tikzpicture}
    \begin{groupplot}[group style={group size=2 by 2,vertical sep= 1.5cm},width=0.45\textwidth,ybar]
      \nextgroupplot[title=title 1-1]
        \addplot coordinates { (1,1) (42,23)};
      \nextgroupplot[title=title 1-2]
        \addplot coordinates { (1,1) (42,23)};
      \nextgroupplot[title=title 2-1]
        \addplot coordinates { (1,1) (42,23)};
      \nextgroupplot[title=title 2-2]
        \addplot coordinates { (1,1) (42,23)};
    \end{groupplot}
  \end{tikzpicture}
\end{document}

enter image description here

2

No you have done it right, however at the moment it does not autocompute the distance required for nice spacing. You can play with the option:

vertical sep=<latex length>

to get the right spacing between them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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