4

I am making a 3x3 matrix of plots in a beamer slide. Position (1,1) is empty, the rest of the first row has column titles and the rest of the first column has row titles. Positions (2,2) to (3,3) contain actual plots. I am using groupplots (pgfplots 1.12) to make such a matrix.

I receive the following two error messages:

Package pgfplots Warning: You have an axis with empty range (in direction y). R eplacing it with a default range and clearing all plots. on input line 139.

! Package pgfplots Error: Error: Plot width `28.45274pt' is too small. This can not be implemented while maintaining constant size for labels. Sorry, label siz es are only approximate. You will need to adjust your width..

In the case of the second error, I don't really know where to increase the width. Can you please help me to fix my code so I don't get the errors mentioned above?

The intended outcome is the following image.

Intended Outcome

My code so far is as follows:

\documentclass{beamer}

\usepackage{pgfplots}
\usetikzlibrary{pgfplots.groupplots}

\pgfplotsset{compat=1.12}

\pgfmathdeclarefunction{gauss}{2}{%
  \pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}


\begin{document}

\begin{frame}{Distribution Matrix}

\begin{tikzpicture}
\begin{groupplot}[
        group style={
            group name=my plots,
            group size=3 by 3,
        },
        footnotesize,
        tickpos=left,
        ytick align=outside,
        xtick align=outside,
        enlarge x limits=false 
    ]

\nextgroupplot[
            width=1cm,
            height=1cm,
            hide axis]

\nextgroupplot[
            width=5cm,
            height=1cm,
            no markers, domain=0:9, samples=100,
            axis line style = { draw = none },
            xlabel style={at={(axis description cs:0.5,-0.01)},anchor=north},
            xlabel={Column 1},
            ticks=none,
            axis on top]

\nextgroupplot[
            width=5cm,
            height=1cm,
            no markers, domain=0:9, samples=100,
            axis line style = { draw = none },
            xlabel style={at={(axis description cs:0.5,-0.01)},anchor=north},
            xlabel={Column 2},
            ticks=none,
            axis on top]

\nextgroupplot[
            width=1cm,
            height=4cm,
            no markers, domain=0:9, samples=100,
            axis lines=center,
            axis line style = { draw = none },
            ylabel style={at={(axis description cs:-0.01,0.5)},rotate=90,anchor=south},
            ylabel={Row 1},
            ticks=none,
            axis on top]

\nextgroupplot[
            width=5cm,
            height=4cm,
            no markers, domain=0:9, samples=100,
            axis lines=center,
            axis line style={->},
            xlabel style={at={(axis description cs:0.5,-0.01)},anchor=north},
            ylabel style={at={(axis description cs:-0.01,0.5)},rotate=90,anchor=south},
            ticks=none,
            axis on top]
    \addplot [very thick,cyan!50!black] {gauss(4,1)};
    \addplot [thick,red, no markers] coordinates {(5.5,0.0) (5.5,0.4)};

\nextgroupplot[
            width=5cm,
            height=4cm,
            no markers, domain=0:9, samples=100,
            axis lines=center,
            axis line style={->},
            xlabel style={at={(axis description cs:0.5,-0.01)},anchor=north},
            ylabel style={at={(axis description cs:-0.01,0.5)},rotate=90,anchor=south},
            ticks=none,
            axis on top]
    \addplot [very thick,cyan!50!black] {gauss(4,1)};
    \addplot [thick,red, no markers] coordinates {(5.5,0.0) (5.5,0.4)};

\nextgroupplot[
            width=1cm,
            height=4cm,
            no markers, domain=0:9, samples=100,
            axis lines=center,
            axis line style = { draw = none },
            ylabel style={at={(axis description cs:-0.01,0.5)},rotate=90,anchor=south},
            ylabel={Row 2},
            ticks=none,
            axis on top]    

\nextgroupplot[
            width=5cm,
            height=4cm,
            no markers, domain=0:9, samples=100,
            axis lines=center,
            axis line style={->},
            xlabel style={at={(axis description cs:0.5,-0.01)},anchor=north},
            ylabel style={at={(axis description cs:-0.01,0.5)},rotate=90,anchor=south},
            ticks=none,
            axis on top]
    \addplot [very thick,cyan!50!black] {gauss(4,1)};
    \addplot [thick,red, no markers] coordinates {(2.5,0) (2.5,0.4)};
    \addplot [thick,red, no markers] coordinates {(5.5,0.0) (5.5,0.4)};

\nextgroupplot[
            width=5cm,
            height=4cm,
            no markers, domain=0:9, samples=100,
            axis lines=center,
            axis line style={->},
            xlabel style={at={(axis description cs:0.5,-0.01)},anchor=north},
            ylabel style={at={(axis description cs:-0.01,0.5)},rotate=90,anchor=south},
            ticks=none,
            axis on top]
    \addplot [dashed,very thick,cyan!50!black] {gauss(4,1)};
    \addplot [very thick,cyan!50!black] {gauss(5,1)};
    \addplot [thick,red, no markers] coordinates {(2.5,0) (2.5,0.4)};
    \addplot [thick,red, no markers] coordinates {(5.5,0.0) (5.5,0.4)};

\end{groupplot}
\end{tikzpicture}
\end{frame}


\end{document}

Thanks in advance!

  • 1
    Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. – user11232 Apr 25 '15 at 2:04
4

You need not use empty \nextgroupplot to insert the Row 1 etc. But use a node like

\node[rotate=90,above=5mm] at (my plots c1r1.west) {Row 1};
\node[rotate=90,above=5mm] at (my plots c1r2.west) {Row 2};
\node[above=5mm] at (my plots c1r1.north) {Column 1};
\node[above=5mm] at (my plots c2r1.north) {Column 2};

The width problem comes as you have width=1cm etc in those empty \nextgroupplots which is very small and pgfplots complains about it.

Here is your refined code:

\documentclass{beamer}

\usepackage{pgfplots}
\usetikzlibrary{pgfplots.groupplots}

\pgfplotsset{compat=1.12}

\pgfmathdeclarefunction{gauss}{2}{%
  \pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}


\begin{document}

\begin{frame}{Distribution Matrix}
%\centering if you want to center this
\begin{tikzpicture}
\begin{groupplot}[
        group style={
            group name=my plots,
            group size=2 by 2,
        },
        footnotesize,
        tickpos=left,
        ytick align=outside,
        xtick align=outside,
        enlarge x limits=false
    ]


\nextgroupplot[
            width=5cm,
            height=4cm,
            no markers, domain=0:9, samples=100,
            axis lines=center,
            axis line style={->},
            xlabel style={at={(axis description cs:0.5,-0.01)},anchor=north},
            ylabel style={at={(axis description cs:-0.01,0.5)},rotate=90,anchor=south},
            ticks=none,
            axis on top]
    \addplot [very thick,cyan!50!black] {gauss(4,1)};
    \addplot [thick,red, no markers] coordinates {(5.5,0.0) (5.5,0.4)};

\nextgroupplot[
            width=5cm,
            height=4cm,
            no markers, domain=0:9, samples=100,
            axis lines=center,
            axis line style={->},
            xlabel style={at={(axis description cs:0.5,-0.01)},anchor=north},
            ylabel style={at={(axis description cs:-0.01,0.5)},rotate=90,anchor=south},
            ticks=none,
            axis on top]
    \addplot [very thick,cyan!50!black] {gauss(4,1)};
    \addplot [thick,red, no markers] coordinates {(5.5,0.0) (5.5,0.4)};

\nextgroupplot[
            width=5cm,
            height=4cm,
            no markers, domain=0:9, samples=100,
            axis lines=center,
            axis line style={->},
            xlabel style={at={(axis description cs:0.5,-0.01)},anchor=north},
            ylabel style={at={(axis description cs:-0.01,0.5)},rotate=90,anchor=south},
            ticks=none,
            axis on top]
    \addplot [very thick,cyan!50!black] {gauss(4,1)};
    \addplot [thick,red, no markers] coordinates {(2.5,0) (2.5,0.4)};
    \addplot [thick,red, no markers] coordinates {(5.5,0.0) (5.5,0.4)};

\nextgroupplot[
            width=5cm,
            height=4cm,
            no markers, domain=0:9, samples=100,
            axis lines=center,
            axis line style={->},
            xlabel style={at={(axis description cs:0.5,-0.01)},anchor=north},
            ylabel style={at={(axis description cs:-0.01,0.5)},rotate=90,anchor=south},
            ticks=none,
            axis on top]
    \addplot [dashed,very thick,cyan!50!black] {gauss(4,1)};
    \addplot [very thick,cyan!50!black] {gauss(5,1)};
    \addplot [thick,red, no markers] coordinates {(2.5,0) (2.5,0.4)};
    \addplot [thick,red, no markers] coordinates {(5.5,0.0) (5.5,0.4)};

\end{groupplot}
\node[rotate=90,above=5mm] at (my plots c1r1.west) {Row 1};
\node[rotate=90,above=5mm] at (my plots c1r2.west) {Row 2};
\node[above=5mm] at (my plots c1r1.north) {Column 1};
\node[above=5mm] at (my plots c2r1.north) {Column 2};
\end{tikzpicture}
\end{frame}


\end{document}

enter image description here

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.