将轴与 \tikzpicture 对齐

将轴与 \tikzpicture 对齐

按照@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}

结果

相关内容