[Tex/LaTex] Shading region of circle with Tikz

tikz-pgf

I am trying to shade in the area of a circle that is cut into three pieces. Here is the code.

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usepackage{tkz-euclide}
\usetikzlibrary{arrows,shadows,positioning, calc, decorations.markings, 
hobby, quotes,angles,decorations.pathreplacing,intersections}
\usepgfplotslibrary{polar}
\usepgflibrary{shapes.geometric}
\usepgfplotslibrary{fillbetween}
\begin{document}

\begin{figure}[ht]

\centering

\begin{tikzpicture}[scale=1.25,line width=1pt]
\begin{axis}[
color= white,
xmin=-15, 
xmax=15, 
ymin=-15, 
ymax=15, 
axis equal image, 
axis lines=middle, 
xticklabels={}, 
yticklabels={},
font=\scriptsize,
ticks=none,
xlabel = {},
ylabel = {},
inner axis line style={stealth-stealth}
]

\draw[black, thick, name path=1] (0,0) circle [radius=12];

\addplot[black, domain=-12:12, samples=300, name path = 1] {sqrt(144-x^2)};

\addplot[black, domain=-12:12, samples=300, name path = 2] {-sqrt(144-x^2)};

\draw[white, name path=3] (-12,0) -- (12,0);

\draw[black, dashed] (-3.179,-11.5713) -- (-3.179,11.5713);

\draw[black, dashed] (3.179,-11.5713) -- (3.179,11.5713);

%\addplot[red, fill opacity=0.20] fill between [of=1 and 2,soft clip= 
{domain=-12:-3.179}];


\end{axis}
\end{tikzpicture}

\caption{Slicing the pie into three pieces of equal area.}

\label{pie}

\end{figure}

\end{document}

Here is the image produced when I leave the last part commented out:

enter image description here

Now, when I uncomment out the last line, this is the result.

enter image description here

While I have the desired shading, the image is now slightly off-center and the axis lines have been drawn, even though I do not want them to. What should I do to fix this?

Best Answer

As for the original question: fillbetween is less "innocent" than one may think, it also sets layers in such a way that the fills are behind the plots. (This is something that I learned from a comment by Stefan Pinnow.) However, the simplest way to get rid of the axes is to say hide axis.

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usepgfplotslibrary{fillbetween}
\begin{document}

\begin{figure}[ht]

\centering

\begin{tikzpicture}[scale=1.25,line width=1pt]
\begin{axis}[hide axis,
xmin=-15, 
xmax=15, 
ymin=-15, 
ymax=15, 
axis equal image, 
font=\scriptsize,
]

\draw[black, thick, name path=1] (0,0) circle [radius=12];

\addplot[black, domain=-12:12, samples=300, name path = 1] {sqrt(144-x^2)};

\addplot[black, domain=-12:12, samples=300, name path = 2] {-sqrt(144-x^2)};


\draw[black, dashed] (-3.179,-11.5713) -- (-3.179,11.5713);

\draw[black, dashed] (3.179,-11.5713) -- (3.179,11.5713);

\addplot[red, fill opacity=0.20] fill between [of=1 and 2,soft clip= 
{domain=-12:-3.179}];
\end{axis}
\end{tikzpicture}
\caption{Slicing the pie into three pieces of equal area.}
\label{pie}
\end{figure}
\end{document}

enter image description here

Yet, if you do not want the axes, why don't you just draw the thing with tikz? (In any case, I'd recommend using polar coordinates for that.)

\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
\begin{tikzpicture}
\draw[clip] (0,0) circle (6);
\fill[red, fill opacity=0.20] (105:6) rectangle (-6,-6);
\draw[dashed] (105:6) -- (-105:6) (75:6) -- (-75:6);
\end{tikzpicture}
\end{document}

enter image description here

Please note also that one can use the pgfplots library fillbetween, see e.g. here. (I'm not claiming that this answer is particularly original, it is just an example that I had at hand.)

As for your last comment: this is what I suggested

\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
\begin{tikzpicture}[thick]
\pgfmathsetmacro{\radius}{4}
\draw[clip] (0,0) circle (\radius);
\fill[red, fill opacity=0.20] (105:\radius) rectangle (-\radius,-\radius);
\fill[blue, fill opacity=0.20] ({-\radius*sin(15)},\radius) rectangle ({\radius*sin(15)},-\radius);
\fill[green, fill opacity=0.20] (75:\radius) rectangle (\radius,-\radius);
\draw[dashed] (105:\radius) -- (-105:\radius) (75:\radius) -- (-75:\radius);
\end{tikzpicture}
\end{document}

and this is what I get

enter image description here