You could make use of the quiver
plot handler which is shipped with pgfplots
. The quiver
plot handler draws arrows at every input sample.
To this end, it requires the input coordinates as usual and arrow coordinates for every input coordinate (i.e. x,y, u, v).
In your case, we could easily sample all required values. Since you have unit vector ratio*=1 1
in your listing, we can normalize all arrows to length 0.1 as follows:
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width=14cm,
axis lines = middle,smooth,xlabel = $x$, ylabel =$y$, minor tick num =1, grid=both, unit vector ratio*=1 1,enlargelimits = true]
\addplot[smooth, thick, -stealth,variable=\t, domain=0:2]
({t^2}, {t^4});
\def\NORM{sqrt((2*t)^2 + (4*t^3)^2)}
\addplot[thick, red,-stealth,samples=12,variable=\t, domain=0.1:2,quiver={
u=2*t/\NORM, v=4*t^3/\NORM,
scale arrows=0.1,
}]
({t^2}, {t^4});
\end{axis}
\end{tikzpicture}
\end{document}
The \NORM
is the vector norm of the vector (u,v)
; together with scale arrows=0.1
, we get the desired effect. Here, we need two \addplot
statements: one which draws the plot as such and one which draws merely the arrows.
For comparison, here is the same figure with scale arrows=1
:
There are few things wrong here. You've not told TikZ that the plot is parametric, you've not put both the x and y components into a single \draw
line and you've not given the formulae in the correct form. You can tell something is up as Gnuplot warns
"test.cos.gnuplot", line 2: undefined variable: t
"test.sin.gnuplot", line 2: undefined variable: t
in the log. Changing the input to
\draw [samples=1000] plot[parametric] function{t+2*sin(2*t),t+2*cos(5*t)};
gives me a plot :it's a one-line change so I've not included everything else. To get your plot, i'd also up the domain to say -7:7
.
Personally, I'd use pgfplots
, which uses the same underlying ideas but is I find easier to read. For example
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
\begin{tikzpicture}
\begin{axis}
[
axis lines = center ,
xtick = {-6.28318,-3.14159,...,6.3} ,
xticklabels = {$-2\pi$, $-\pi$, $0$, $\pi$, $2\pi$} ,
ytick = {-6.28318,-3.14159,...,6.3} ,
yticklabels = {$-2\pi$, $-\pi$, $0$, $\pi$, $2\pi$}
]
\addplot[domain = -7:7, parametric, samples = 1000]
gnuplot {t+2*sin(2*t),t+2*cos(5*t)};
\end{axis}
\end{tikzpicture}
\end{document}
which gives
Best Answer
Another fun with PSTricks. It really uses the parametric approach in question.
Notes for ShareLaTeX users
Go to upper left menu, and you will see the following. Change as pointed by the red arrow. And don't forget to recompile.
The lastest update based on OP's comment