tikz.dev / PGFplots Manual

Manual for Package pgfplots
2D/3D Plots in LA, Version 1.18.1
http://sourceforge.net/projects/pgfplots

Related Libraries

\(\newcommand{\footnotename}{footnote}\) \(\def \LWRfootnote {1}\) \(\newcommand {\footnote }[2][\LWRfootnote ]{{}^{\mathrm {#1}}}\) \(\newcommand {\footnotemark }[1][\LWRfootnote ]{{}^{\mathrm {#1}}}\) \(\let \LWRorighspace \hspace \) \(\renewcommand {\hspace }{\ifstar \LWRorighspace \LWRorighspace }\) \(\newcommand {\mathnormal }[1]{{#1}}\) \(\newcommand \ensuremath [1]{#1}\) \(\newcommand {\LWRframebox }[2][]{\fbox {#2}} \newcommand {\framebox }[1][]{\LWRframebox } \) \(\newcommand {\setlength }[2]{}\) \(\newcommand {\addtolength }[2]{}\) \(\newcommand {\setcounter }[2]{}\) \(\newcommand {\addtocounter }[2]{}\) \(\newcommand {\arabic }[1]{}\) \(\newcommand {\number }[1]{}\) \(\newcommand {\noalign }[1]{\text {#1}\notag \\}\) \(\newcommand {\cline }[1]{}\) \(\newcommand {\directlua }[1]{\text {(directlua)}}\) \(\newcommand {\luatexdirectlua }[1]{\text {(directlua)}}\) \(\newcommand {\protect }{}\) \(\def \LWRabsorbnumber #1 {}\) \(\def \LWRabsorbquotenumber "#1 {}\) \(\newcommand {\LWRabsorboption }[1][]{}\) \(\newcommand {\LWRabsorbtwooptions }[1][]{\LWRabsorboption }\) \(\def \mathchar {\ifnextchar "\LWRabsorbquotenumber \LWRabsorbnumber }\) \(\def \mathcode #1={\mathchar }\) \(\let \delcode \mathcode \) \(\let \delimiter \mathchar \) \(\def \oe {\unicode {x0153}}\) \(\def \OE {\unicode {x0152}}\) \(\def \ae {\unicode {x00E6}}\) \(\def \AE {\unicode {x00C6}}\) \(\def \aa {\unicode {x00E5}}\) \(\def \AA {\unicode {x00C5}}\) \(\def \o {\unicode {x00F8}}\) \(\def \O {\unicode {x00D8}}\) \(\def \l {\unicode {x0142}}\) \(\def \L {\unicode {x0141}}\) \(\def \ss {\unicode {x00DF}}\) \(\def \SS {\unicode {x1E9E}}\) \(\def \dag {\unicode {x2020}}\) \(\def \ddag {\unicode {x2021}}\) \(\def \P {\unicode {x00B6}}\) \(\def \copyright {\unicode {x00A9}}\) \(\def \pounds {\unicode {x00A3}}\) \(\let \LWRref \ref \) \(\renewcommand {\ref }{\ifstar \LWRref \LWRref }\) \( \newcommand {\multicolumn }[3]{#3}\) \(\require {textcomp}\) \( \newcommand {\meta }[1]{\langle \textit {#1}\rangle } \) \(\newcommand {\toprule }[1][]{\hline }\) \(\let \midrule \toprule \) \(\let \bottomrule \toprule \) \(\def \LWRbooktabscmidruleparen (#1)#2{}\) \(\newcommand {\LWRbooktabscmidrulenoparen }[1]{}\) \(\newcommand {\cmidrule }[1][]{\ifnextchar (\LWRbooktabscmidruleparen \LWRbooktabscmidrulenoparen }\) \(\newcommand {\morecmidrules }{}\) \(\newcommand {\specialrule }[3]{\hline }\) \(\newcommand {\addlinespace }[1][]{}\) \(\require {colortbl}\) \(\let \LWRorigcolumncolor \columncolor \) \(\renewcommand {\columncolor }[2][named]{\LWRorigcolumncolor [#1]{#2}\LWRabsorbtwooptions }\) \(\let \LWRorigrowcolor \rowcolor \) \(\renewcommand {\rowcolor }[2][named]{\LWRorigrowcolor [#1]{#2}\LWRabsorbtwooptions }\) \(\let \LWRorigcellcolor \cellcolor \) \(\renewcommand {\cellcolor }[2][named]{\LWRorigcellcolor [#1]{#2}\LWRabsorbtwooptions }\) \(\newcommand {\intertext }[1]{\text {#1}\notag \\}\) \(\let \Hat \hat \) \(\let \Check \check \) \(\let \Tilde \tilde \) \(\let \Acute \acute \) \(\let \Grave \grave \) \(\let \Dot \dot \) \(\let \Ddot \ddot \) \(\let \Breve \breve \) \(\let \Bar \bar \) \(\let \Vec \vec \) \(\newcommand {\nicefrac }[3][]{\mathinner {{}^{#2}\!/\!_{#3}}}\)

5.8Grouping plots

by Nick Papior Andersen

  • \usepgfplotslibrary{groupplots} % and plain

  • \usepgfplotslibrary[groupplots] % Cont

  • \usetikzlibrary{pgfplots.groupplots} % and plain

  • \usetikzlibrary[pgfplots.groupplots] % Cont

  • A library which allows the user to typeset several plots in a matrix like structure. Often one has to compare two plots to one another, or you simply need to display two plots in conjunction with each other. Either way the following section describes this library which makes matrix structure easier than alternative methods discussed in Section 4.19.4.

  • \begin{groupplot}[(math image)options(math image)]

  • (math image)environment contents(math image)

  • \end{groupplot}

  • Once you have loaded the groupplots library you will gain access to this environment. This environment is limited to the same restrictions as the axis environment. It actually utilizes this environment so consider it as an extension of this. What is important to note is that [(math image)options(math image)] are applied to all plots in the entire environment. This can be really handy when you need the same xmin, xmax, ymin and ymax.

With such an environment one can typeset plots in matrix like styles

(-tikz- diagram)   (-tikz- diagram)

% Preamble: \pgfplotsset{width=7cm,compat=1.18}\usepgfplotslibrary{groupplots} % Example using groupplots library \begin{tikzpicture} \begin{groupplot}[group style={group size=2 by 2},height=3cm,width=3cm] \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} \qquad % Same example created as done without the library \begin{tikzpicture} \begin{axis}[name=plot1,height=3cm,width=3cm] \addplot coordinates {(0,0) (1,1) (2,2)}; \end{axis} \begin{axis}[name=plot2,at={($(plot1.east)+(1cm,0)$)},anchor=west,height=3cm,width=3cm] \addplot coordinates {(0,2) (1,1) (2,0)}; \end{axis} \begin{axis}[name=plot3,at={($(plot1.south)-(0,1cm)$)},anchor=north,height=3cm,width=3cm] \addplot coordinates {(0,2) (1,1) (2,1)}; \end{axis} \begin{axis}[name=plot4,at={($(plot2.south)-(0,1cm)$)},anchor=north,height=3cm,width=3cm] \addplot coordinates {(0,2) (1,1) (1,0)}; \end{axis} \end{tikzpicture}

The equivalent code is seen as the second example and it is clear that you have to type a lot less. So how do you use it? First of all you need to utilize the new environment groupplot. Within this environment the following command works.

5.8.1Grouping options
  • /pgfplots/group style={(math image)options with group/ prefix(math image)}

  • This key sets all (math image)options(math image) using the /pgfplots/group/ prefix.

    Note that the distinction between group/ and normal options is important as some of them are quite similar.

    For example, the following statements are all equivalent:

    \pgfplotsset{group style={a=2,b=3}} \pgfplotsset{group/a=2,group/b=3} \pgfplotsset{group/.cd,a=2,b=3}

All the following keys are in the subdirectory group.

  • /pgfplots/group/group size=(math image)columns(math image) by (math image)rows(math image) (initially 1 by 1)

  • /pgfplots/group/columns=(math image)columns(math image) (initially 1)

  • /pgfplots/group/rows=(math image)rows(math image) (initially 1)

  • These keys determine the total number of plots that can be in one environment groupplot. It is thus important not to add more \nextgroupplot in the environment than (math image)columns(math image)\(\times \)(math image)rows(math image). This is critical to set if one uses more than 1 more plot. As the key group size uses columns and rows you should stick to either group size or both columns and rows.

  • /pgfplots/group/horizontal sep=(math image)dimension(math image) (initially 1cm)

  • /pgfplots/group/vertical sep=(math image)dimension(math image) (initially 1cm)

  • The spacing between the plots in the horizontal and vertical direction, respectively. If you thus want them to be glued together you should set them both to a length of 0pt.

  • /pgfplots/group/every plot/.style={(math image)style(math image)} (initially empty)

  • This style is used on every plot as the first style. It is thus equivalent as (math image)options(math image) in the groupplot environment.

  • /pgfplots/group/xticklabels at=all|edge top|edge bottom (initially all)

  • /pgfplots/group/yticklabels at=all|edge left|edge right (initially all)

  • In order to determine which plots get tick labels typeset one can use these keys. By default all axes gets typeset normally and thus have both \(x\)- and \(y\)-axis tick labels. If one sets

    \pgfplotsset{ group/xticklabels at=edge bottom, group/yticklabels at=edge right, }

    only the bottom row gets tick labels on the \(x\)-axis and only the last column gets tick labels on the \(y\)-axis on their right side. These keys are specially handy when using glued plots.

    Keep in mind that this is implies the same ticks for all plots.