4

How does one insert arbitary placed arrows along a curve/function defined in pgfplots using the \plot command. I realise the last sentence became a tad long.. Below is a simple code for which I am trying to insert arrows, if I had points to go after, I could have used something like Pgfplots: Drawing Arrows Along Contour Plots or decorations. But this does not work here...

Earlier i asked the same question with the draw function Add arrows to a smooth tikz function, and obtained a really good answer. However implementing the solution directly to the code under gives missfortunate 'stack overflow' error. To summarize

  • Is there a way to place a number of arrows a long a function / curve made with pgfplots?

Presumably with a similar syntax to

\draw plot ... [arrow inside={end=stealth,opt={scale=2}}{0.25,0.5,0.75}];

Here is one figure I am trying to add a few arrows too

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\tikzset{
    set arrow inside/.code={\pgfqkeys{/tikz/arrow inside}{#1}},
    set arrow inside={end/.initial=>, opt/.initial=},
    /pgf/decoration/Mark/.style={
        mark/.expanded=at position #1 with
        {
            \noexpand\arrow[\pgfkeysvalueof{/tikz/arrow inside/opt}]{\pgfkeysvalueof{/tikz/arrow inside/end}}
        }
    },
    arrow inside/.style 2 args={
        set arrow inside={#1},
        postaction={
            decorate,decoration={
                markings,Mark/.list={#2}
            }
        }
    },
}
\begin{document}
\begin{tikzpicture}
\draw node [circle] at (-1,0) {$z_0$};
\begin{scope}[very thick,rotate=45,decoration={
    markings,
    mark=at position 0.5 with {\arrow{>}}}]
\draw[domain=0:6.28,samples=200,smooth,] plot (xy polar
cs:angle=\x r,radius=      {1-sin(2*\x r)}) ;
\end{scope}
\end{tikzpicture} 
\end{document}

Lemniscate

2
  • Are you committed to doing this with pgfplots? It's easy enough in Metapost - you can make your function a path and then draw arrows along subpaths of it.
    – Thruston
    Mar 9, 2014 at 18:28
  • I can't see any use of pgfplots in your question. Is there a particular reason for that? Because I already have an answer for your MWE. Mar 9, 2014 at 23:56

1 Answer 1

8

As you didn't answer my comment yet, I will just post my solution to the problem I think you are trying to solve.

You may just use the code, given in my answer to this question: Add arrows to a smooth tikz function Next you will need to remove the smooth statement, because it will interfere with decorate and give you nice errors like ? Dimension too large. This won't have an effect on the smoothness of your drawing, because you already use sufficiently many samples.

Implementation

\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\tikzset{
  set arrow inside/.code={\pgfqkeys{/tikz/arrow inside}{#1}},
  set arrow inside={end/.initial=>, opt/.initial=},
  /pgf/decoration/Mark/.style={
    mark/.expanded=at position #1 with
    {
      \noexpand\arrow[\pgfkeysvalueof{/tikz/arrow inside/opt}]{\pgfkeysvalueof{/tikz/arrow inside/end}}
    }
  },
  arrow inside/.style 2 args={
    set arrow inside={#1},
    postaction={
      decorate,decoration={
        markings,Mark/.list={#2}
      }
    }
  },
}
\begin{document}
\begin{tikzpicture}
  \draw node [circle] at (-1,0) {$z_0$};
  \begin{scope}[very thick,rotate=45]
    \draw[domain=0:6.28,samples=200] plot (xy polar cs:angle=\x r,radius={1-sin(2*\x r)}) [arrow inside={}{0.25,0.5,0.75}];
  \end{scope}
\end{tikzpicture} 
\end{document}

Output

enter image description here

1
  • 1
    You may add -- cycle to close the curve. Mar 13, 2014 at 6:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .