考虑由
\documentclass[]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{filecontents}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{filecontents}{tmp}
\draw[fill, gray!20] (0,0) rectangle (1,1);
\end{filecontents}
\begin{tikzpicture}
\begin{axis}
\input{tmp};
\addplot coordinates
{
(0, 0)
(1, 1)
(1, 0)
};
\end{axis}
\end{tikzpicture}
\end{document}
当我将键xshift
和yshift
轴添加到
\begin{axis}[xshift=2,yshift=2]
我希望数字能够发生变化,但是却没有发生,为什么呢?
我发现的另一种方法是使用scope
和x filter
:y filter
\documentclass[]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{filecontents}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{filecontents}{tmp}
\draw[fill, gray!20] (0,0) rectangle (1,1);
\draw[red] (0, 0) -- (1,0.5);
\end{filecontents}
\begin{tikzpicture}
\begin{axis}[]
\begin{scope}[shift={(1,1)}] % Putting (2,2) gives the correct shift, why?
\input{tmp}
\end{scope}
\addplot
[
x filter/.expression = {x+1},
y filter/.expression = {y+1}
]
coordinates
{
(0, 0)
(1, 1)
(1, 0)
};
\end{axis}
\end{tikzpicture}
\end{document}
但是为了正确移动矩形,我需要的begin{scope}[shift={(2,2)}]
是 而不是begin{scope}[shift={(1,1)}]
,为什么?