Beamer 中 pgfplot 的 groupplot 出現繪圖寬度錯誤

Beamer 中 pgfplot 的 groupplot 出現繪圖寬度錯誤

我正在投影機幻燈片中製作 3x3 的繪圖矩陣。位置 (1,1) 為空,第一行的其餘部分具有列標題,第一列的其餘部分具有行標題。位置 (2,2) 到 (3,3) 包含實際繪圖。我正在使用groupplotspgfplots1.12)來製作這樣一個矩陣。

我收到以下兩個錯誤訊息:

包 pgfplots 警告:您有一個範圍為空的軸(沿 y 方向)。 R 將其替換為預設範圍並清除所有繪圖。在輸入行 139 上。

!包 pgfplots 錯誤:錯誤:繪圖寬度“28.45274pt”太小。在保持標籤大小恆定的情況下無法實現這一點。抱歉,標籤尺寸只是近似值。你需要調整你的寬度..

在第二個錯誤的情況下,我真的不知道在哪裡增加寬度。您能幫我修復我的程式碼,這樣我就不會收到上述錯誤嗎?

預期結果如下圖所示。

預期結果

到目前為止我的程式碼如下:

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

先致謝!

答案1

您不需要使用空\nextgroupplot來插入Row 1等。

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

寬度問題出現width=1cm在那些空的\nextgroupplots 中,它非常小並且pgfplots抱怨它。

這是您的改進程式碼:

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

在此輸入影像描述

相關內容