3

I want to draw circles as node on polar curve r=1+cos(x) with equal intervals. I can draw one node on curve, say for 30 degree, using parametric equation of curve using code below.

\documentclass[margin=1cm]{standalone}
\usepackage{pgf,tikz,pgfplots}
\usepackage{amsmath,amssymb,amsfonts,amsthm}
\usetikzlibrary{calc,arrows}
\pgfplotsset{compat=1.12} 
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    axis lines=center,
    axis equal image,
    enlargelimits=true,
    xlabel=$x$,
    ylabel=$y$
     ]
    \addplot[data cs=polar,orange,domain=0:360,samples=360,smooth, ultra thick] (x,{1+cos(x)});
    \pgfmathsetmacro{\R}{1+cos(30)};%
    \fill (30:\R) circle (2pt); 
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

For others nodes, inserting using \foreach, I give errors as follows:

 \addplot[data cs=polar,orange,domain=0:360,samples=360,smooth, ultra thick] (x,{1+cos(x)});
    \foreach \t in {0,10,20,...,360}
    {
    \pgfmathsetmacro{\R}{1+cos(\t)};
    \fill (\t:\R) circle (2pt);
    }  

! Undefined control sequence.
\UseTextAccent ...up \@firstofone \let \@curr@enc
\cf@encoding \@use@text@en...
l.21 \end{axis}

How can I achive this? Thank you in advance.

  • 1
    Related: http://tex.stackexchange.com/questions/170664/foreach-not-behaving-in-axis-environment – Enlico Feb 12 '17 at 13:24
  • @EnricoMariaDeAngelis, thank you. It got it. –  Feb 12 '17 at 13:54
  • @ferafeza, I added a more concise answer. If you even needed to add labels to each of the markes, I would still try to rely on pgfplots tools before falling back on tikz's unrivaled power. – Enlico Feb 12 '17 at 14:05

1 Answers1

4

enter image description here By the way, an even more concise way of doing what you want is to rely on another addplot with only marks, mark=*, black, and samples=36 options, as follows.

\documentclass[margin=1cm]{standalone}
\usepackage{pgf,tikz,pgfplots}
\usepackage{amsmath,amssymb,amsfonts,amsthm}
\usetikzlibrary{calc,arrows}
\pgfplotsset{compat=1.12} 
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    axis lines=center,
    axis equal image,
    enlargelimits=true,
    xlabel=$x$,
    ylabel=$y$
     ]
    \addplot[data cs=polar,orange,domain=0:360,samples=360,smooth, ultra thick] (x,{1+cos(x)});
    \addplot[data cs=polar,domain=0:360,samples=36,mark=*,only marks,black] (x,{1+cos(x)});
\end{axis}
\end{tikzpicture}
\end{document}
Enlico
  • 2,592