Drawing a picture without overlay of the grid

tikz-pgf

The following TikZ code produces the image below. It's a tiny detail but I do not want the 3pt thick black lines to be overlayed by the grid. However, if I place the grid before, then the interior part of the yellow fill does not have the grid anymore. Ideally I would like to have this order of appearance : the exterior part of the 3pt line (which appears on the image below) > yellow fill > grid. However, this seems to impose to be able to draw directly the appearing 3pt line, which I did not manage to do : I draw to circles and then fill above in the interior part. Thanks for any help !

\begin{tikzpicture}
\draw [line width = 3pt] (0.5,0) circle (1.5cm);
\draw [line width = 3pt] (-0.5,0) circle (1.5cm);
\fill [yellow] (0.5,0) circle (1.5cm);
\fill [yellow] (-0.5,0) circle (1.5cm);
\draw[step=5mm, help lines, color=gray!30] (-2.9,-2.9) grid (2.9,2.9);
\draw[->,thick] (-3,0)--(3,0) node[right]{$x$};
\draw[->,thick] (0,-3)--(0,3) node[above]{$y$};
\end{tikzpicture}

enter image description here

Best Answer

Your yellow fill covers half of your line. I preserve this by doing it like this. To make the grid on top of the yellow fill, simply draw it again, but only inside the same area like this:

\documentclass[tikz, border = 1cm] {standalone}
\begin{document}    
\begin{tikzpicture}
\draw[step=5mm, help lines, color=gray!30] (-2.9,-2.9) grid (2.9,2.9);
\draw [line width = 3pt] (0.5,0) circle (1.5cm);
\draw [line width = 3pt] (-0.5,0) circle (1.5cm);
\fill [yellow] (0.5,0) circle (1.5cm);
\fill [yellow] (-0.5,0) circle (1.5cm);
\begin{scope}
\clip(-0.5,0) circle (1.5cm) (0.5,0) circle (1.5cm);
\draw[step=5mm, help lines, color=gray!30] (-2.9,-2.9) grid (2.9,2.9);
\end{scope}
\draw[->,thick] (-3,0)--(3,0) node[right]{$x$};
\draw[->,thick] (0,-3)--(0,3) node[above]{$y$};
\end{tikzpicture}
\end{document}

Yellow birings

Related Question