Shading region of circle with Tikz












2















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?










share|improve this question




















  • 1





    You are missing usepgfplotslibrary{fillbetween} and end{document}, and when I add these I cannot reproduce the issue you are reporting.

    – marmot
    Jan 27 at 0:43











  • Sorry about that. I added all of the tikz libraries I had in this, so maybe it could be one of those. I have just been adding them as a learn how to draw more with tikz, so maybe that could be the issue?

    – Aiden Kenny
    Jan 27 at 0:57











  • Yes, I think so. Using fillbetween does more than one may expect. It also sets layers (because the fills are made behind the plots) . With hide axis you can solve it, though.

    – marmot
    Jan 27 at 1:02
















2















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?










share|improve this question




















  • 1





    You are missing usepgfplotslibrary{fillbetween} and end{document}, and when I add these I cannot reproduce the issue you are reporting.

    – marmot
    Jan 27 at 0:43











  • Sorry about that. I added all of the tikz libraries I had in this, so maybe it could be one of those. I have just been adding them as a learn how to draw more with tikz, so maybe that could be the issue?

    – Aiden Kenny
    Jan 27 at 0:57











  • Yes, I think so. Using fillbetween does more than one may expect. It also sets layers (because the fills are made behind the plots) . With hide axis you can solve it, though.

    – marmot
    Jan 27 at 1:02














2












2








2








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?










share|improve this question
















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?







tikz-pgf






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 27 at 0:56







Aiden Kenny

















asked Jan 27 at 0:28









Aiden KennyAiden Kenny

3677




3677








  • 1





    You are missing usepgfplotslibrary{fillbetween} and end{document}, and when I add these I cannot reproduce the issue you are reporting.

    – marmot
    Jan 27 at 0:43











  • Sorry about that. I added all of the tikz libraries I had in this, so maybe it could be one of those. I have just been adding them as a learn how to draw more with tikz, so maybe that could be the issue?

    – Aiden Kenny
    Jan 27 at 0:57











  • Yes, I think so. Using fillbetween does more than one may expect. It also sets layers (because the fills are made behind the plots) . With hide axis you can solve it, though.

    – marmot
    Jan 27 at 1:02














  • 1





    You are missing usepgfplotslibrary{fillbetween} and end{document}, and when I add these I cannot reproduce the issue you are reporting.

    – marmot
    Jan 27 at 0:43











  • Sorry about that. I added all of the tikz libraries I had in this, so maybe it could be one of those. I have just been adding them as a learn how to draw more with tikz, so maybe that could be the issue?

    – Aiden Kenny
    Jan 27 at 0:57











  • Yes, I think so. Using fillbetween does more than one may expect. It also sets layers (because the fills are made behind the plots) . With hide axis you can solve it, though.

    – marmot
    Jan 27 at 1:02








1




1





You are missing usepgfplotslibrary{fillbetween} and end{document}, and when I add these I cannot reproduce the issue you are reporting.

– marmot
Jan 27 at 0:43





You are missing usepgfplotslibrary{fillbetween} and end{document}, and when I add these I cannot reproduce the issue you are reporting.

– marmot
Jan 27 at 0:43













Sorry about that. I added all of the tikz libraries I had in this, so maybe it could be one of those. I have just been adding them as a learn how to draw more with tikz, so maybe that could be the issue?

– Aiden Kenny
Jan 27 at 0:57





Sorry about that. I added all of the tikz libraries I had in this, so maybe it could be one of those. I have just been adding them as a learn how to draw more with tikz, so maybe that could be the issue?

– Aiden Kenny
Jan 27 at 0:57













Yes, I think so. Using fillbetween does more than one may expect. It also sets layers (because the fills are made behind the plots) . With hide axis you can solve it, though.

– marmot
Jan 27 at 1:02





Yes, I think so. Using fillbetween does more than one may expect. It also sets layers (because the fills are made behind the plots) . With hide axis you can solve it, though.

– marmot
Jan 27 at 1:02










1 Answer
1






active

oldest

votes


















3














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






share|improve this answer


























  • Can you explain the coordinates used when shaping the red? I am also trying to shade in all three areas using different colors, so I would like to know!

    – Aiden Kenny
    Jan 27 at 1:15











  • Also for me, when I use hide axis, the image is still off center and there is a blank white line across the red shaded region.

    – Aiden Kenny
    Jan 27 at 1:20






  • 1





    @AidenKenny Your coordinate (-3.179,11.5713) looks very much like (-12*sin(15),12*cos(15)), which is (95:12) in polar coordinates. The clip option makes sure that only the region in the circle gets shaded. So I shade a rectangle with upper right corner (95:6) (because I reduced the radius) and a lower left corner that is far away enough. As for your pgfplots comment: I removed the white line from my code, did you compile the code from my answer?

    – marmot
    Jan 27 at 1:21











  • @AidenKenny To color all regions, try e.g. 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}

    – marmot
    Jan 27 at 1:26











  • The code for filling in all of the regions does not work completely. There are two colored rectangles but they do not fill in the entire circle.

    – Aiden Kenny
    Jan 27 at 1:58











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f472038%2fshading-region-of-circle-with-tikz%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









3














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






share|improve this answer


























  • Can you explain the coordinates used when shaping the red? I am also trying to shade in all three areas using different colors, so I would like to know!

    – Aiden Kenny
    Jan 27 at 1:15











  • Also for me, when I use hide axis, the image is still off center and there is a blank white line across the red shaded region.

    – Aiden Kenny
    Jan 27 at 1:20






  • 1





    @AidenKenny Your coordinate (-3.179,11.5713) looks very much like (-12*sin(15),12*cos(15)), which is (95:12) in polar coordinates. The clip option makes sure that only the region in the circle gets shaded. So I shade a rectangle with upper right corner (95:6) (because I reduced the radius) and a lower left corner that is far away enough. As for your pgfplots comment: I removed the white line from my code, did you compile the code from my answer?

    – marmot
    Jan 27 at 1:21











  • @AidenKenny To color all regions, try e.g. 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}

    – marmot
    Jan 27 at 1:26











  • The code for filling in all of the regions does not work completely. There are two colored rectangles but they do not fill in the entire circle.

    – Aiden Kenny
    Jan 27 at 1:58
















3














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






share|improve this answer


























  • Can you explain the coordinates used when shaping the red? I am also trying to shade in all three areas using different colors, so I would like to know!

    – Aiden Kenny
    Jan 27 at 1:15











  • Also for me, when I use hide axis, the image is still off center and there is a blank white line across the red shaded region.

    – Aiden Kenny
    Jan 27 at 1:20






  • 1





    @AidenKenny Your coordinate (-3.179,11.5713) looks very much like (-12*sin(15),12*cos(15)), which is (95:12) in polar coordinates. The clip option makes sure that only the region in the circle gets shaded. So I shade a rectangle with upper right corner (95:6) (because I reduced the radius) and a lower left corner that is far away enough. As for your pgfplots comment: I removed the white line from my code, did you compile the code from my answer?

    – marmot
    Jan 27 at 1:21











  • @AidenKenny To color all regions, try e.g. 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}

    – marmot
    Jan 27 at 1:26











  • The code for filling in all of the regions does not work completely. There are two colored rectangles but they do not fill in the entire circle.

    – Aiden Kenny
    Jan 27 at 1:58














3












3








3







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






share|improve this 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







share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 27 at 2:01

























answered Jan 27 at 0:40









marmotmarmot

97k4112213




97k4112213













  • Can you explain the coordinates used when shaping the red? I am also trying to shade in all three areas using different colors, so I would like to know!

    – Aiden Kenny
    Jan 27 at 1:15











  • Also for me, when I use hide axis, the image is still off center and there is a blank white line across the red shaded region.

    – Aiden Kenny
    Jan 27 at 1:20






  • 1





    @AidenKenny Your coordinate (-3.179,11.5713) looks very much like (-12*sin(15),12*cos(15)), which is (95:12) in polar coordinates. The clip option makes sure that only the region in the circle gets shaded. So I shade a rectangle with upper right corner (95:6) (because I reduced the radius) and a lower left corner that is far away enough. As for your pgfplots comment: I removed the white line from my code, did you compile the code from my answer?

    – marmot
    Jan 27 at 1:21











  • @AidenKenny To color all regions, try e.g. 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}

    – marmot
    Jan 27 at 1:26











  • The code for filling in all of the regions does not work completely. There are two colored rectangles but they do not fill in the entire circle.

    – Aiden Kenny
    Jan 27 at 1:58



















  • Can you explain the coordinates used when shaping the red? I am also trying to shade in all three areas using different colors, so I would like to know!

    – Aiden Kenny
    Jan 27 at 1:15











  • Also for me, when I use hide axis, the image is still off center and there is a blank white line across the red shaded region.

    – Aiden Kenny
    Jan 27 at 1:20






  • 1





    @AidenKenny Your coordinate (-3.179,11.5713) looks very much like (-12*sin(15),12*cos(15)), which is (95:12) in polar coordinates. The clip option makes sure that only the region in the circle gets shaded. So I shade a rectangle with upper right corner (95:6) (because I reduced the radius) and a lower left corner that is far away enough. As for your pgfplots comment: I removed the white line from my code, did you compile the code from my answer?

    – marmot
    Jan 27 at 1:21











  • @AidenKenny To color all regions, try e.g. 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}

    – marmot
    Jan 27 at 1:26











  • The code for filling in all of the regions does not work completely. There are two colored rectangles but they do not fill in the entire circle.

    – Aiden Kenny
    Jan 27 at 1:58

















Can you explain the coordinates used when shaping the red? I am also trying to shade in all three areas using different colors, so I would like to know!

– Aiden Kenny
Jan 27 at 1:15





Can you explain the coordinates used when shaping the red? I am also trying to shade in all three areas using different colors, so I would like to know!

– Aiden Kenny
Jan 27 at 1:15













Also for me, when I use hide axis, the image is still off center and there is a blank white line across the red shaded region.

– Aiden Kenny
Jan 27 at 1:20





Also for me, when I use hide axis, the image is still off center and there is a blank white line across the red shaded region.

– Aiden Kenny
Jan 27 at 1:20




1




1





@AidenKenny Your coordinate (-3.179,11.5713) looks very much like (-12*sin(15),12*cos(15)), which is (95:12) in polar coordinates. The clip option makes sure that only the region in the circle gets shaded. So I shade a rectangle with upper right corner (95:6) (because I reduced the radius) and a lower left corner that is far away enough. As for your pgfplots comment: I removed the white line from my code, did you compile the code from my answer?

– marmot
Jan 27 at 1:21





@AidenKenny Your coordinate (-3.179,11.5713) looks very much like (-12*sin(15),12*cos(15)), which is (95:12) in polar coordinates. The clip option makes sure that only the region in the circle gets shaded. So I shade a rectangle with upper right corner (95:6) (because I reduced the radius) and a lower left corner that is far away enough. As for your pgfplots comment: I removed the white line from my code, did you compile the code from my answer?

– marmot
Jan 27 at 1:21













@AidenKenny To color all regions, try e.g. 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}

– marmot
Jan 27 at 1:26





@AidenKenny To color all regions, try e.g. 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}

– marmot
Jan 27 at 1:26













The code for filling in all of the regions does not work completely. There are two colored rectangles but they do not fill in the entire circle.

– Aiden Kenny
Jan 27 at 1:58





The code for filling in all of the regions does not work completely. There are two colored rectangles but they do not fill in the entire circle.

– Aiden Kenny
Jan 27 at 1:58


















draft saved

draft discarded




















































Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f472038%2fshading-region-of-circle-with-tikz%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to change which sound is reproduced for terminal bell?

Can I use Tabulator js library in my java Spring + Thymeleaf project?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents