我正在制作投影仪幻灯片中的 3x3 绘图矩阵。位置 (1,1) 为空,第一行的其余部分有列标题,第一列的其余部分有行标题。位置 (2,2) 至 (3,3) 包含实际绘图。我使用groupplots
( pgfplots
1.12) 制作这样的矩阵。
我收到以下两条错误消息:
包 pgfplots 警告:您的轴有空范围(在 y 方向上)。用默认范围替换它并清除所有图。在输入行 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
在那些空的\nextgroupplot
s 中遇到的那样,它们非常小并且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}