按照@Jake 对该问题的回答\addplot 和 \draw,我设置了如下代码:
\documentclass{standalone}
\usepackage{tikz, pgfplots}
\def\points{
(1, 1)
(2, 2)
}
\begin{document}
\begin{tikzpicture}
\draw[thick, color=red](1, 1) -- (2, 2);
\begin{axis}[anchor = origin, x = 1cm, y = 1cm, hide axis]
\addplot [color = blue] coordinates {\points};
\end{axis}
\end{tikzpicture}
\end{document}
结果是
显然axis
和\tikzpicture
没有正确对齐。哪里出了问题?
答案1
设置xmin=0, ymin=0
修复了该问题:
\documentclass{standalone}
\usepackage{tikz, pgfplots}
\def\points{
(1, 1)
(2, 2)
}
\begin{document}
\begin{tikzpicture}
\draw[thick, color=red](1, 1) -- (2, 2);
\begin{axis}[anchor = origin, x = 1cm, y = 1cm, hide axis, xmin=0, ymin=0]
\addplot [color = blue] coordinates {\points};
\end{axis}
\end{tikzpicture}
\end{document}