1

I found this question in which it is explained how to draw a bouquet of n circles and this question explains how to draw an arrow on each line. I wanted to combine those two answers to draw a bouquet of n circles such that each circle has an arrow head in the middle, but combining the two questions gives a bouquet of n circles with arrows all over the place. I was wondering if anyone knew how to adjust either of those answers to fix my problem.

Also, I would remove one of the petals and replace them by some dots (to show that there are n petals). I can remove one petal by restricting the domain of the drawing command, but how to get the dots?

I know this is probably not a good question, but I looked into the PGF manual and still could not come up with a nice result, so any help would be greatly appreciated.

EDIT I added code which is basically the answers of the two linked questions combined, but don't know how to make it appear in grey square as the other answers do (I look at the edit button of those answers to see if there is some command needed, but did not find this).

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,decorations.markings}
\usepackage{pgfplots}
\usepgfplotslibrary{polar}
\pgfplotsset{compat=newest}

\begin{document}
\tikzset{
  % style to apply some styles to each segment of a path
  on each segment/.style={
    decorate,
    decoration={
      show path construction,
      moveto code={},
      lineto code={
        \path [#1]
        (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
      },
      curveto code={
        \path [#1] (\tikzinputsegmentfirst)
        .. controls
        (\tikzinputsegmentsupporta) and (\tikzinputsegmentsupportb)
        ..
        (\tikzinputsegmentlast);
      },
      closepath code={
        \path [#1]
        (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
      },
    },
  },
  % style to add an arrow in the middle of a path
  mid arrow/.style={postaction={decorate,decoration={
        markings,
        mark=at position .5 with {\arrow[#1]{stealth}}
      }}},
}

 \begin{tikzpicture}
\begin{polaraxis}
\addplot[mark=none,domain=0:360,samples=300,postaction={on each segment={mid arrow=red}}] {cos(5*x)};
\end{polaraxis}
\end{tikzpicture}
\end{document}
1
  • You need to place 4 whitespace chars at the start of each line or select code and click the {} to mark things as code block
    – percusse
    Apr 3, 2018 at 16:14

1 Answer 1

1

Minimal version (with dots):

\documentclass[tikz,border=5pt]{standalone}

\begin{document}
\begin{tikzpicture}
\def\bouquetN{5}
\pgfmathsetmacro{\MaxAng}{360/\bouquetN}
\foreach \X in {2,...,\bouquetN}
{
\draw[blue,-latex,thick] (0,0)
to[out={\MaxAng*\X-\MaxAng/4},in={\MaxAng*\X-90}] ({\MaxAng*\X+2}:3);
\draw[blue,thick] (0,0)
to[out={\MaxAng*\X+\MaxAng/4},in={\MaxAng*\X+90}] ({\MaxAng*\X}:3);
}
\foreach \X in {-1,0,1}
{\draw[blue,fill=blue] ({\MaxAng+\X*\MaxAng/4}:2.4) circle (4pt); }
\end{tikzpicture}
\end{document}

enter image description here

Following the codes from the links: The reason why your code produces tons of arrows it that you put it on each segment. If you were to increase samples even more, you'd get more arrows. If you only want to put the arrows specific points, you may use

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,decorations.markings}
\usepackage{pgfplots}
\usepgfplotslibrary{polar}
\pgfplotsset{compat=newest}

\begin{tikzpicture}
\begin{polaraxis}
\addplot[mark=none,domain=0:360,samples=300,postaction={
decorate,decoration={markings, mark=at position .1 with {\arrow{stealth}},
mark=at position .3 with {\arrow{stealth}},
mark=at position .5 with {\arrow{stealth}},
mark=at position .7 with {\arrow{stealth}},
mark=at position .9 with {\arrow{stealth}}
}}] {cos(5*x)};
\end{polaraxis}
\end{tikzpicture}
\end{document}

enter image description here

Here, the positions derive from the requirement that there need to be 5 equally spaced points. So, if you'd plot cos(4*x) instead, you'd have four positions at 0.125, 0.375, 0.625 and 0.875, and so on. In principle one could write a macro that finds these positions. However, I'd rather not go this way because to the best of my knowledge you can't bend the arrows this way.

Therefore, I'd like to argue that you may want to do it with elementary TikZ syntax rather than pgfplots because then it is more straightforward to bend the arrows. (I understand that you may not necessarily want them be bent, but other people may.)

\documentclass[tikz,border=5pt]{standalone}
\usetikzlibrary{arrows.meta,bending}

\begin{document}
\begin{tikzpicture}
\def\bouquetN{3}
\foreach \X in {1,...,\bouquetN}
{\pgfmathsetmacro{\MaxAng}{360/\bouquetN}
\draw[blue,-{Latex[length=2mm,bend]},thick] (0,0)
to[out={\MaxAng*\X-\MaxAng/4},in={\MaxAng*\X-90}] ({\MaxAng*\X+2}:3);
\draw[blue,thick] (0,0)
to[out={\MaxAng*\X+\MaxAng/4},in={\MaxAng*\X+90}] ({\MaxAng*\X}:3);
}
\end{tikzpicture}
\end{document}

enter image description here

With \def\bouquetN{4}:

enter image description here

There is also a dot mentioned in the title of the question but I don't know where to put it.

6
  • Thank you! I meant to remove one circle and instead draw $\ldots$ (as you use in a set, when you leave out elements, but people know what elements that are)
    – Student
    Apr 3, 2018 at 17:14
  • @Student OK, I added the dots and also an explanation why I wouldn't recommend to use pgfplots here.
    – user121799
    Apr 3, 2018 at 17:26
  • thank you! I am on mobile now, but the pictures are what I had in mind, so that's great :)
    – Student
    Apr 3, 2018 at 17:30
  • one last question: is it also possible to use regular arrows instead of the stealth-like ones? I guess you draw those in the line where you have the bend-option, so I am not sure...
    – Student
    Apr 3, 2018 at 18:01
  • 1
    @Student Yes, just replace \draw[blue,-{Latex[length=4mm,bend]},thick] (0,0) by \draw[blue,->,thick] (0,0) or \draw[blue,-latex,thick] (0,0). In this case, you do not need to load the libraries arrows.meta nor bending (and decorations is also never used in the pure TikZ examples).
    – user121799
    Apr 3, 2018 at 18:03

You must log in to answer this question.

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