How can I color fill the annulus with tikz?
Things are drawn in the order in which they're defined, so if you draw lines first and fill afterwards, the filling will cover the lines. To fill only the region between the inner and outer circle, you can add the following at the very start of your diagram (right after \begin{tikzpicture}[...]
)
\fill [red,even odd rule] (0,0) circle[radius=2cm] circle[radius=1cm];
In the code below I introduce some other techniques to draw your diagram. The circles are drawn using a loop, the r_N
labels are appended at the end of the radial lines, which themselves are drawn using polar coordinates (<angle>:<radius>)
I didn't include the name path
stuff, as you didn't seem to be using it for anything, and I removed x=1cm,y=1cm
and color=black
, because those are the default anyway. I also replaced the triangle 45
arrow tip from the arrows
library with Triangle
from arrows.meta
, as pgf
considers the former library to be deprecated in favor of the latter.
\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}[
line cap=round,
line join=round,
>=Triangle,
myaxis/.style={->,thick}
]
\fill [red,even odd rule] (0,0) circle[radius=2cm] circle[radius=1cm];
\foreach \radius in {1,1.5,2}
\draw [thick] (0,0) circle[radius=\radius cm];
\begin{scope}[
every node/.append style={
circle,
font=\scriptsize,
inner sep=1pt
}]
\node at (135:2.5cm) {$R$};
% The following \foreach does the same as the three \draws immediately below
%\foreach [count=\i] \Ang/\Rad in {40/1,75/1.5,55/2}
% \draw [thick] (0,0) -- (\Ang:\Rad cm) node[anchor=180+\Ang] {$r_{\i}$};
\draw [thick] (0,0) -- (40:1cm) node[anchor=220] {$r_1$};
\draw [thick] (0,0) -- (55:2cm) node[anchor=235] {$r_3$};
\draw [thick] (0,0) -- (75:1.5cm) node[anchor=255] {$r_2$};
\end{scope}
\draw[myaxis] (-3.66,0) -- (3.66,0);
\draw[myaxis] (0,-3.66) -- (0,3.66);
\end{tikzpicture}
\end{document}
Like this? The order of drawing circles and lines matters. Also, you needn't say draw=black
, it's the default.
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
\draw [name path=B, thick, draw,fill=blue!20](0,0) circle (2cm);
\draw [name path=C, thick, draw](0,0) circle (1.5cm);
\draw [name path=A, thick, draw,fill=white](0,0) circle (1cm);
\draw [thick](0,0)-- (0.76,0.64);
\draw [thick](0,0)-- (1.13,1.65);
\draw [thick](0,0)-- (0.37,1.45);
\draw[->, thick] (-3.66,0) -- (3.66,0);
\draw[->, thick] (0,-3.66) -- (0,3.66);
\begin{scriptsize}
\draw (-1.54,1.94) node {$R$};
\draw (1.11,0.73) node {$r_1$};
\draw (1.48,1.81) node {$r_3$};
\draw (0.55,1.69) node {$r_2$};
\end{scriptsize}
\end{tikzpicture}