指向轴环境内的箭头

指向轴环境内的箭头

我正在制作一个显示笛卡尔平面上绘制点的图像。我使用的是axis来自的环境pgfplots。它可以很好地绘制点,但我似乎无法弄清楚将箭头放在哪里以显示运动。我可以尝试计算位置,但似乎应该有更好的方法。

工作部分是:

\usepackage{tikz,pgfplots}     %for graphics
\pgfplotsset{compat = newest}     %to run newest version
\usetikzlibrary{calc,tikzmark,arrows,arrows.meta,positioning}

\begin{document}
\begin{tikzpicture}
\begin{axis}[xmin=-5, xmax=5, ymin=-5, ymax=5, 
axis lines=middle, myaxis, xtick = {-4,-3,-2,-1,0,1,2,3,4}, ytick = {-4,-3,-2,-1,0,1,2,3,4},
xlabel = \(x\), ylabel = \(y\)]
    \addplot+[only marks] coordinates {(0,1) (-2,4) (1,-3)};
\end{axis}
\end{tikzpicture}
\end{document}

我试过:

\begin{tikzpicture}
\begin{axis}[xmin=-5, xmax=5, ymin=-5, ymax=5, 
axis lines=middle, myaxis, xtick = {-4,-3,-2,-1,0,1,2,3,4}, ytick = {-4,-3,-2,-1,0,1,2,3,4},
xlabel = \(x\), ylabel = \(y\)]

    \addplot+[only marks] coordinates {(0,1) (-2,4) (1,-3)};
\end{axis}

\draw[green,-latex, very thick] (0,0) -- (0,1);
\draw[blue,latex-, very thick] (0,0) -- (-2,0);
\draw[blue,-latex, very thick] (-2,0) -- (-2,4);
\draw[gray,-latex, very thick] (0,0) -- (1,0);
\draw[gray,-latex, very thick] (1,0) -- (1,-3);
\end{tikzpicture}

但这却惨遭失败。

答案1

使用axis坐标系来引用图表中的点。为此,\draw需要在axis环境内使用该操作。

现在,您可以使用(axis cs: <x>, <y>)参考点 (X) 在您的图表中。

\documentclass[tikz]{standalone}
\usepackage{pgfplots}     %for graphics
\pgfplotsset{compat = newest}     %to run newest version
\usetikzlibrary{arrows}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
  xmin=-5, xmax=5, ymin=-5, ymax=5,
  axis lines=middle,
  %myaxis, % don't know this
  xtick = {-4,-3,-2,-1,0,1,2,3,4},
  ytick = {-4,-3,-2,-1,0,1,2,3,4},
  xlabel = \(x\),
  ylabel = \(y\)
]

\addplot+[only marks] coordinates {(0,1) (-2,4) (1,-3)};

\draw[green,-latex, very thick](axis cs: 0,0) -- (axis cs: 0, 1);
\draw[blue,latex-, very thick] (axis cs: 0,0) -- (axis cs:-2, 0);
\draw[blue,-latex, very thick] (axis cs:-2,0) -- (axis cs:-2, 4);
\draw[gray,-latex, very thick] (axis cs: 0,0) -- (axis cs: 1, 0);
\draw[gray,-latex, very thick] (axis cs: 1,0) -- (axis cs: 1,-3);
\end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容