[Tex/LaTex] Centering group plot figure

groupplotspgfplotstikz-pgf

Can anyone show me how to center this group plot? I've tried every trick in the tex.stackexchange book of similar posts (e.g., How to center large figures in LaTeX and how to fix short justified lines?).

\documentclass[]{article}
    \usepackage{pgfplots, alphalph}
    \usepgfplotslibrary{groupplots}

\begin{document}

\begin{figure}
    \begin{tikzpicture}[font=\footnotesize\sffamily]
      \begin{groupplot}[
         group style={group size=3 by 2, vertical sep=70pt,
    ylabels at=edge left
    },
          view={0}{90},
          width=5.2cm,
          height=5.2cm,
      scale only axis,
      scaled ticks = false,
      tick label style={/pgf/number format/fixed},
      title={My title},
      xlabel={x-axis},
      ylabel={y-axis}],
          unbounded coords=jump]
        ]
        \nextgroupplot [title={\it{Title 1}}]       
\addplot[black, thick, mark=o, only marks]
    coordinates {
        };

        \nextgroupplot [title={\it{Title 2}}]      
\addplot[black, thick, mark=o, only marks]
    coordinates {
        };

        \nextgroupplot [title={\it{Title 3}}]      
\addplot[black, thick, mark=o, only marks]
    coordinates {
        };

        \nextgroupplot [title={\it{Title 4}}]      
\addplot[black, thick, mark=o, only marks]
    coordinates {
        };

        \nextgroupplot [title={\it{Title 5}}]      
\addplot[black, thick, mark=o, only marks]
    coordinates {
        };

         \end{groupplot}

    \end{tikzpicture}
  \end{figure}



\end{document}

Best Answer

Your plots are too wide. You may try to put 2 plots in a row instead of 3. However, there is always this box techniques that can be used.

\documentclass[]{article}
    \usepackage{pgfplots, alphalph}
    \usepgfplotslibrary{groupplots}

\begin{document}

\begin{figure}
\makebox[\textwidth]{%
    \begin{tikzpicture}[font=\footnotesize\sffamily]
      \begin{groupplot}[
         group style={group size=3 by 2, vertical sep=70pt,
    ylabels at=edge left
    },
          view={0}{90},
          width=5.2cm,
          height=5.2cm,
      scale only axis,
      scaled ticks = false,
      tick label style={/pgf/number format/fixed},
      title={My title},
      xlabel={x-axis},
      ylabel={y-axis}],
          unbounded coords=jump]
        ]
        \nextgroupplot [title={\it{Title 1}}]
\addplot[black, thick, mark=o, only marks]
    coordinates {
        };

        \nextgroupplot [title={\it{Title 2}}]
\addplot[black, thick, mark=o, only marks]
    coordinates {
        };

        \nextgroupplot [title={\it{Title 3}}]
\addplot[black, thick, mark=o, only marks]
    coordinates {
        };

        \nextgroupplot [title={\it{Title 4}}]
\addplot[black, thick, mark=o, only marks]
    coordinates {
        };

        \nextgroupplot [title={\it{Title 5}}]
\addplot[black, thick, mark=o, only marks]
    coordinates {
        };

         \end{groupplot}

    \end{tikzpicture}
    }
  \end{figure}




\end{document}

enter image description here

If in case, you want to center the last two plots, you may use a suitable width for all plots (so that you know how much to shift) and use xshift like

\nextgroupplot [xshift=1.2in,title={\it{Title 4}}]
\addplot[black, thick, mark=o, only marks]
    coordinates {
        };

        \nextgroupplot [xshift=1.2in,title={\it{Title 5}}]
\addplot[black, thick, mark=o, only marks]
    coordinates {
        };

enter image description here

With table:

\documentclass[]{article}
    \usepackage{pgfplots, alphalph}
    \usepgfplotslibrary{groupplots}
\usepackage{filecontents}
 \begin{filecontents*}{mydata.dat}
  A   B      
  1    4
  2    6
  3    9
  4    2
  5    3
  \end{filecontents*}

\begin{document}

\begin{figure}
\makebox[\textwidth]{%
    \begin{tikzpicture}[font=\footnotesize\sffamily]
      \begin{groupplot}[
         group style={group size=3 by 2, vertical sep=70pt,
    ylabels at=edge left
    },
          view={0}{90},
          width=5.2cm,
          height=5.2cm,
      scale only axis,
      scaled ticks = false,
      tick label style={/pgf/number format/fixed},
      title={My title},
      xlabel={x-axis},
      ylabel={y-axis}],
          unbounded coords=jump]
        ]
        \nextgroupplot [title={\it{Title 1}}]
\addplot[black, thick, mark=o, only marks]
    table[x=A,y=B]{mydata.dat};

        \nextgroupplot [title={\it{Title 2}}]
\addplot[black, thick, mark=o, only marks]
    table[x=A,y=B]{mydata.dat};

        \nextgroupplot [title={\it{Title 3}}]
\addplot[black, thick, mark=o, only marks]
    table[x=A,y=B]{mydata.dat};

        \nextgroupplot [title={\it{Title 4}}]
\addplot[black, thick, mark=o, only marks]
    table[x=A,y=B]{mydata.dat};

        \nextgroupplot [title={\it{Title 5}}]
\addplot[black, thick, mark=o, only marks]
    table[x=A,y=B]{mydata.dat};

         \end{groupplot}

    \end{tikzpicture}
    }
  \end{figure}




\end{document}

and with

        \nextgroupplot [xshift=1.2in,title={\it{Title 4}}]
\addplot[black, thick, mark=o, only marks]
    table[x=A,y=B]{mydata.dat};

        \nextgroupplot [xshift=1.2in,title={\it{Title 5}}]
\addplot[black, thick, mark=o, only marks]
    table[x=A,y=B]{mydata.dat};

enter image description here