2

I'm attempting to use just Tikz to shade in the region within the polar plot but outside of the internal circle as seen in the screenshot below...

I understand that pgf plots might be the better package to use, although I am very unfamiliar with it, speaking of which I'm very new to Tikz as well. This is my first post here, as I am unable to find previous posts that answer this particular question. Any help is appreciated. Thank you

[ ]

This is the code that I have completed so far, but as you can see, I'm struggling to un-shade the internal circle.

\documentclass[border=5mm]{standalone}   
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[>=latex]

% cartesian coordinates
\draw[-] (-1cm,0cm) -- (3cm,0cm) node[right,fill=white] {$x$};
\draw[-] (0cm,-2cm) -- (0cm,2cm) node[above,fill=white] {$y$};

% axis labels and tick marks
\foreach \x in {-1,0,...,3}
    \draw(\x,3pt) -- (\x,-3pt) node[fill=white, below] {\footnotesize$\x$};

\foreach \y in {-2,-1,...,2}
    \draw(-3pt,\y) -- (3pt,\y) node[fill=white, right] {\footnotesize$\y$};

% cosine graph
\draw [thick,color=black,domain=0:2*pi,samples=200,smooth] plot (xy polar 
cs:angle=\x r,radius= {1+1*cos(\x r)});
\draw [thick,color=black,domain=0:2*pi,samples=200,smooth] plot (xy polar 
cs:angle=\x r,radius= {cos(\x r)});

% shading
\fill [fill=gray!50!white, opacity=0.3] plot [domain=0:2*pi] (xy polar 
cs:angle=\x r,radius= {1+1*cos(\x r)});

\end{tikzpicture} 
\end{document}

The following picture is what this code produced... enter image description here

2

By building the circle with the circle operation and not with the plot operation, it is possible to use the even odd rule. (see page 172 of 3.0.1a TikZ's manual).

Update: By applying the fill opacity=.3 parameter

as indicated by @marmot in its commentary.

even odd rule

\documentclass[border=5mm]{standalone}   
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[>=latex]

% cartesian coordinates
\draw[-] (-1cm,0cm) -- (3cm,0cm) node[right,fill=white] {$x$};
\draw[-] (0cm,-2cm) -- (0cm,2cm) node[above,fill=white] {$y$};

% axis labels and tick marks
\foreach \x in {-1,0,...,3}
    \draw(\x,3pt) -- (\x,-3pt) node[fill=white, below] {\footnotesize$\x$};

\foreach \y in {-2,-1,...,2}
    \draw(-3pt,\y) -- (3pt,\y) node[fill=white, right] {\footnotesize$\y$};

% cosine graph
\filldraw [thick,even odd rule,fill=gray!50,fill opacity=.3,domain=0:2*pi,samples=200,smooth] plot (xy polar 
cs:angle=\x r,radius= {1+1*cos(\x r)})(0.5,0)circle(5mm);

\end{tikzpicture} 
\end{document}
  • Is there a way to make the plotted shape outline black instead of a darker gray? Also brilliant work, thank you! – salami_pirate Dec 18 '18 at 4:28
  • 1
    @salami_pirate Yes, by using fill opacity=0.3 instead of opacity=0.3. – marmot Dec 18 '18 at 4:35

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.