I have to plot a few parametric curves like the one on the left below, and I would like to add small arrows to represent the direction of the plot as parameter t increases from 0 to π. I know how to add arrows on a curve using postaction=decorate
as shown on the right example, but this does not appear to work on curves rendered by \datavisualization
. Is there any other way to do it?
Essentially I would just like to equip the left plot with those blue arrows.
Here is the code I have for the above picture:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{datavisualization}
\usetikzlibrary{datavisualization.formats.functions}
\begin{document}
\begin{tikzpicture}[decoration={markings,
mark=between positions 0 and 1 step 3mm
with { \arrow[blue]{>};}}]
% Decoration works here...
\draw[red,postaction=decorate] (2,0) to[out=-90,in=85] (4,0);
% ...but is ignored here.
\datavisualization[school book axes,
visualize as smooth line=f,
all axes={include value/.list={1,-1}},
f={style={red,postaction=decorate}}
]
data [format=function,set=f] {
var t : interval [0:pi] samples 50;
func x = cos(3 * \value{t}r) * cos(\value{t}r);
func y = cos(3 * \value{t}r) * sin(\value{t}r);
};
\end{tikzpicture}
\end{document}
EDIT: Two days later, I realized I could work around this by drawing the function in several pieces as follows:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{spy}
\usetikzlibrary{datavisualization}
\usetikzlibrary{datavisualization.formats.functions}
\begin{document}
\begin{tikzpicture}[spy using outlines={circle, magnification=5, size=1cm, connect spies}]
\foreach \i in {1,...,6}
\datavisualization[school book axes,
visualize as smooth line=f,
all axes={include value/.list={1,-1}},
f={style={red,->[blue]}}
]
data [format=function,set=f] {
var t : interval [pi*(\i-.5)/6:pi*(\i+.5)/6] samples 10;
func x = cos(3 * \value{t}r) * cos(\value{t}r);
func y = cos(3 * \value{t}r) * sin(\value{t}r);
};
\spy [green] on (.72,0.18) in node (zoom) at (.8, 1);
\end{tikzpicture}
\end{document}
However this has several drawbacks:
- decomposition of the range in six parts is really dependent on the function I'm drawing,
- I'm drawing the axes 6 times on top of each other and for some reason this produce thicker axes,
- because the arrow tip is not flat, there is some gap between the end of one function piece and the start of the next one (as shown by the spy node).