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.

Using the groupplots library in pgfplots, how can a title be set for a group of plots? The following code (basically from the manual) is an example layout. I don't want each plot to have a title, but rather a title be placed centered on top of the group.

\documentclass[crop,tikz]{standalone}

\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}

\begin{document}

\begin{tikzpicture}
  \begin{groupplot}[
    group style={
      {group size=2 by 2}},
    height=3cm,width=3cm,
    title={Title}]

    \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}

sample groupplot

share|improve this question
add comment

2 Answers

up vote 18 down vote accepted

You can use a TikZ node as a title for a quick solution.

\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{calc}
\usepgfplotslibrary{groupplots}
\begin{document}
\begin{tikzpicture}
  \begin{groupplot}[group style={group size=2 by 2},height=3cm,width=3cm]
    \nextgroupplot[title=One]
    \addplot coordinates {(0,0) (1,1) (2,2)};
    \nextgroupplot[title=Two]
    \addplot coordinates {(0,2) (1,1) (2,0)};
    \nextgroupplot[title=Three]
    \addplot coordinates {(0,2) (1,1) (2,1)};
    \nextgroupplot[title=Four]
    \addplot coordinates {(0,2) (1,1) (1,0)};
  \end{groupplot}
\node (title) at ($(group c1r1.center)!0.5!(group c2r1.center)+(0,2cm)$) {THE Title};
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
6  
Since I don't intend on having individual plot titles, I used \node (title) at ($(group c1r1.north)!0.5!(group c2r1.north)$) [above, yshift=\pgfkeysvalueof{/pgfplots/every axis title shift}] to simulate how pgfplots places the title using axis description cs. –  sappjw Apr 6 '12 at 18:30
    
@sappjw Yep, that's a neat solution. –  percusse Apr 6 '12 at 18:35
add comment

You can also use the \matrix command to group plots together inside of a single tickzpicture, and add the title to the created tickzpicture:

% Preamble: \pgfplotsset{width=7cm,compat=1.9}
\begin{tikzpicture}
    \pgfplotsset{small}
    \matrix {
        \begin{axis}
            \addplot {x};
        \end{axis}
        &
        % differently large labels are aligned automatically:
        \begin{axis}[ylabel={$f(x)=x^2$},ylabel style={font=\Huge}]
            \addplot {x^2};
        \end{axis}
        \\
        %
        \begin{axis}[xlabel=$x$,xlabel style={font=\Huge}]
            \addplot {x^3};
        \end{axis}
        &
        \begin{axis}
            \addplot {x^4};
        \end{axis}
        \\
        };
\end{tikzpicture}

enter image description here

(the title isn't added here but you just need to add it on top of the matrix command) More information about the PGFPLOTS package in the PGFPlot Manual.

share|improve this answer
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.