我正在尝试沿参数曲线的路径添加方向箭头。我已经知道如何制作下面的曲线(忽略红色抛物线):
\begin{document}
\section{2D Plots}
\begin{tikzpicture}
\begin{axis}[xmin=-10, xmax=10, ymin=-10, ymax=10,
axis lines=middle,
xlabel = $x$,
ylabel = $y$]
\addplot[color=red]{4-x^2};
\addplot[ domain=0:5*pi,
samples = 120, color = blue]
({2*cos(deg(2*x))},
{4*sin(deg(3*x)});
\end{axis}
\end{tikzpicture}
\end{document}
答案1
在pgfplots
文档部分 4.17.4 将装饰放置在图的顶部。
Smooth
图在连续点之间平滑插入。使用fpu
,可以更精确地进行装饰。
\documentclass[border=5mm]{standalone}
%https://tex.stackexchange.com/questions/717063/adding-direction-arrows-for-a-parametric-graph
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usetikzlibrary{decorations.markings,fpu}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xmin=-10, xmax=10, ymin=-10, ymax=10,
axis lines=middle,
xlabel = $x$,
ylabel = $y$]
\addplot[
/pgf/fpu/install only=veclen,smooth,%<-- added
blue,samples=127,domain=0:5*pi,
postaction={decorate},% ------
decoration={markings, % ------
mark=between positions .0 and 1. step .25 with {\arrow{stealth}},
% mark=at position 0.25 with {\arrow{stealth}},
% mark=at position 0.5 with {\arrow{stealth}},
% mark=at position 0.75 with {\arrow{stealth}}
}
]({2*cos(deg(2*x))},{4*sin(deg(3*x)});
\end{axis}
\end{tikzpicture}
\end{document}