5

I am trying to plot some circles with a black edge and white face color. The circles are placed on the edge of an ellipse. I cannot figure out why this code is not working:

\documentclass{minimal}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}
    \shadedraw [inner color=black!10,outer color=black!60,domain=0:2*pi] plot ({2*cos(\x r)},{1*sin(\x r)});
    \foreach \a in {0,0.6283,...,6.2832}
           {
               % I was expecting circles with a black edge
               \fill [black,fill=white] ({2*cos(\a r)},{1*sin(\a r)}) circle (4pt);
           }
\end{tikzpicture}
\end{document}

This is what I get (the circle edges are either white or are not drawn at all):

enter image description here

Thanks!

5

Use draw=black or \filldraw. As Grimler also says, with \fill the color is only applied as as a fill color. You're not telling TikZ to draw the shape, only fill it, and the fill color is set to white. By adding draw=black the shape is drawn as well, with the specified color. With \filldraw[black,fill=white] the outline of the shape is drawn in black, and filled with white. (Actually, the order is first filling, then drawing.)

enter image description here

\documentclass{article}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}
    \shadedraw [inner color=black!10,outer color=black!60,domain=0:2*pi] plot ({2*cos(\x r)},{1*sin(\x r)});
    \foreach \a in {0,0.6283,...,6.2832}
           {
           % \filldraw [black,fill=white] ({2*cos(\a r)},{1*sin(\a r)}) circle (4pt);
               \fill [draw=black,fill=white] ({2*cos(\a r)},{1*sin(\a r)}) circle (4pt);
           }
\end{tikzpicture}
\end{document}
  • Great, that works. I wasn't aware that the draw key was needed. – Tobs Oct 29 '15 at 15:50
1

Or use \filldraw. May be you want to clip too and more samples so as to have a smoother ellipse..

\documentclass{article}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}[,line width=1.4\pgflinewidth]
    \clip [domain=0:2*pi,samples=500] plot ({2*cos(\x r)},{1*sin(\x r)});
    \shadedraw [inner color=black!10,outer color=black!60,domain=0:2*pi,samples=500] plot ({2*cos(\x r)},{1*sin(\x r)});
    \foreach \a in {0,0.6283,...,6.2832}
           {
               % I was expecting circles with a black edge
               \filldraw [black,fill=white,line width=0.7\pgflinewidth] ({2*cos(\a r)},{1*sin(\a r)}) circle (4pt);
           }
\end{tikzpicture}
\end{document}

enter image description here

  • Thank you Harish, I'll increase the samples as you recommended. – Tobs Oct 29 '15 at 15:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.