不使用 groupplots 对图进行分组

不使用 groupplots 对图进行分组

运行此 MWE:

\documentclass{article}
\usepackage{pgfplots}
\begin{document}

\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[%
width=2in, height=2in,
scale only axis, xmin=0,
xmax=7, xtick={\empty}, ymin=-1, ymax=1.1
]
\addplot [color=blue,solid,forget plot]
  table[row sep=crcr]{0 0\\
};
\end{axis}
\end{tikzpicture}%

\begin{tikzpicture}
\begin{axis}[%
width=2in, height=2in,
scale only axis, xmin=0,
xmax=7, xtick={\empty}, ymin=-1, ymax=1.1
]
\addplot [color=blue,solid,forget plot]
  table[row sep=crcr]{0 0\\
};
\end{axis}
\end{tikzpicture}%
\end{figure}

\end{document}

给我这个图像:

示例图

我想将这些图表合并起来,使它们共享相同的 x 轴。但我想在不使用的情况下执行此操作groupplots,因为我将使用 生成单独的 .tikz 文件matlab2tikz,而我宁愿设置它,以便我可以在 latex 中对它们进行分组。(matlab2tikz不能很好地处理子图。

我想要的结果是(使用油漆):

合并图

不必担心 y 轴,在导出之前,MATLAB 会使用正确的比例对其进行整理。

编辑 - 感谢您的评论,是的,我很乐意编辑和的内容\begin{tikzpicture}\end{tikzpicture}只要编辑的内容不是将第二个数据集复制到其中,那么我不妨放弃这个想法并继续groupplots。谢谢

谢谢

答案1

您可以注释掉或删除一个\end{tikzpicture}和以下内容\begin{tikzpicture}以使两个axis环境处于相同的 中tikzpicture。然后,您可以为第一个轴指定一个name,并将第二个轴相对于它放置。

\documentclass{article}
\usepackage{pgfplots}
\begin{document}

\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[%
width=2in, height=2in,
scale only axis, xmin=0,
xmax=7, xtick={\empty}, ymin=-1, ymax=1.1,
name=first % <-- added
]
\addplot [color=blue,solid,forget plot]
  table[row sep=crcr]{0 0\\
};
\end{axis}
%\end{tikzpicture}% <--   commented

%\begin{tikzpicture} % <-- commented
\begin{axis}[%
width=2in, height=2in,
scale only axis, xmin=0,
xmax=7, xtick={\empty}, ymin=-1, ymax=1.1,
at={(first.south west)},anchor=north west % <-- added
]
\addplot [color=blue,solid,forget plot]
  table[row sep=crcr]{0 0\\
};
\end{axis}
\end{tikzpicture}%
\end{figure}

\end{document}

在此处输入图片描述

相关内容