I want to color a graph
Im very new to making latex so all the tutorials I have found about my question were too hard to understand or didn't do exactly what I wanted.
I already have the graph I want without the coloring:
begin{figure}
centering
begin{tikzpicture}
draw[->] (-2,0) -- (2,0) node[right] {$x$};
draw[->] (0,-2) -- (0,2) node[above] {$y$};
draw[scale=0.4,domain=-1.71:1.71,smooth,variable=x,black] plot ({x},{(x)^3});
end{tikzpicture}
end{figure}
tikz-pgf
New contributor
|
show 1 more comment
Im very new to making latex so all the tutorials I have found about my question were too hard to understand or didn't do exactly what I wanted.
I already have the graph I want without the coloring:
begin{figure}
centering
begin{tikzpicture}
draw[->] (-2,0) -- (2,0) node[right] {$x$};
draw[->] (0,-2) -- (0,2) node[above] {$y$};
draw[scale=0.4,domain=-1.71:1.71,smooth,variable=x,black] plot ({x},{(x)^3});
end{tikzpicture}
end{figure}
tikz-pgf
New contributor
1
(written without compiling)fill [green] (-2,0) plot [domain=0:1.26] (x,x^3) |- cycle;
– Symbol 1
9 hours ago
Oh i didnt know it was that easy! It looks good, but because of the scale=0.4, the green area isnt correctly under the graph. How to i re-scale the green area?
– Hans
8 hours ago
I figured it out! i just added it in the square brackets:fill [green, scale=0.4] (-2,2) plot [domain=0:0.5] (x,x^3) |- cycle;
– Hans
8 hours ago
But how do I color even farther out to the right like I drew on the paper? And how to color the other four areas?
– Hans
8 hours ago
Either you specify coordinates carefully (e.g.1.26
in my code in cubic root of2
) or useclip
– Symbol 1
8 hours ago
|
show 1 more comment
Im very new to making latex so all the tutorials I have found about my question were too hard to understand or didn't do exactly what I wanted.
I already have the graph I want without the coloring:
begin{figure}
centering
begin{tikzpicture}
draw[->] (-2,0) -- (2,0) node[right] {$x$};
draw[->] (0,-2) -- (0,2) node[above] {$y$};
draw[scale=0.4,domain=-1.71:1.71,smooth,variable=x,black] plot ({x},{(x)^3});
end{tikzpicture}
end{figure}
tikz-pgf
New contributor
Im very new to making latex so all the tutorials I have found about my question were too hard to understand or didn't do exactly what I wanted.
I already have the graph I want without the coloring:
begin{figure}
centering
begin{tikzpicture}
draw[->] (-2,0) -- (2,0) node[right] {$x$};
draw[->] (0,-2) -- (0,2) node[above] {$y$};
draw[scale=0.4,domain=-1.71:1.71,smooth,variable=x,black] plot ({x},{(x)^3});
end{tikzpicture}
end{figure}
tikz-pgf
tikz-pgf
New contributor
New contributor
New contributor
asked 9 hours ago
HansHans
132
132
New contributor
New contributor
1
(written without compiling)fill [green] (-2,0) plot [domain=0:1.26] (x,x^3) |- cycle;
– Symbol 1
9 hours ago
Oh i didnt know it was that easy! It looks good, but because of the scale=0.4, the green area isnt correctly under the graph. How to i re-scale the green area?
– Hans
8 hours ago
I figured it out! i just added it in the square brackets:fill [green, scale=0.4] (-2,2) plot [domain=0:0.5] (x,x^3) |- cycle;
– Hans
8 hours ago
But how do I color even farther out to the right like I drew on the paper? And how to color the other four areas?
– Hans
8 hours ago
Either you specify coordinates carefully (e.g.1.26
in my code in cubic root of2
) or useclip
– Symbol 1
8 hours ago
|
show 1 more comment
1
(written without compiling)fill [green] (-2,0) plot [domain=0:1.26] (x,x^3) |- cycle;
– Symbol 1
9 hours ago
Oh i didnt know it was that easy! It looks good, but because of the scale=0.4, the green area isnt correctly under the graph. How to i re-scale the green area?
– Hans
8 hours ago
I figured it out! i just added it in the square brackets:fill [green, scale=0.4] (-2,2) plot [domain=0:0.5] (x,x^3) |- cycle;
– Hans
8 hours ago
But how do I color even farther out to the right like I drew on the paper? And how to color the other four areas?
– Hans
8 hours ago
Either you specify coordinates carefully (e.g.1.26
in my code in cubic root of2
) or useclip
– Symbol 1
8 hours ago
1
1
(written without compiling)
fill [green] (-2,0) plot [domain=0:1.26] (x,x^3) |- cycle;
– Symbol 1
9 hours ago
(written without compiling)
fill [green] (-2,0) plot [domain=0:1.26] (x,x^3) |- cycle;
– Symbol 1
9 hours ago
Oh i didnt know it was that easy! It looks good, but because of the scale=0.4, the green area isnt correctly under the graph. How to i re-scale the green area?
– Hans
8 hours ago
Oh i didnt know it was that easy! It looks good, but because of the scale=0.4, the green area isnt correctly under the graph. How to i re-scale the green area?
– Hans
8 hours ago
I figured it out! i just added it in the square brackets:
fill [green, scale=0.4] (-2,2) plot [domain=0:0.5] (x,x^3) |- cycle;
– Hans
8 hours ago
I figured it out! i just added it in the square brackets:
fill [green, scale=0.4] (-2,2) plot [domain=0:0.5] (x,x^3) |- cycle;
– Hans
8 hours ago
But how do I color even farther out to the right like I drew on the paper? And how to color the other four areas?
– Hans
8 hours ago
But how do I color even farther out to the right like I drew on the paper? And how to color the other four areas?
– Hans
8 hours ago
Either you specify coordinates carefully (e.g.
1.26
in my code in cubic root of 2
) or use clip
– Symbol 1
8 hours ago
Either you specify coordinates carefully (e.g.
1.26
in my code in cubic root of 2
) or use clip
– Symbol 1
8 hours ago
|
show 1 more comment
3 Answers
3
active
oldest
votes
A tricky way:
documentclass[tikz,margin=3mm]{standalone}
begin{document}
begin{tikzpicture}
fill[blue!20] (-2,-2) rectangle (2,2);
fill[green!50] (0,0)--({-1.71*0.4},{0.4*(-1.71^3)})--(2,-2)--(2,0)--cycle;
fill[green!50] (0,0)--({1.71*0.4},{0.4*(1.71^3)})--(-2,2)--(-2,0)--cycle;
draw[->] (-2,0) -- (2,0) node[right] {$x$};
draw[->] (0,-2) -- (0,2) node[above] {$y$};
draw[scale=0.4,domain=-1.71:1.71,smooth,variable=x,black,fill=green!50] plot ({x},{(x)^3});
end{tikzpicture}
end{document}
We see a line that joins the two ends of the curve.
– AndréC
8 hours ago
That looks exactly like i want it! But is there any way to get around that slightly visible dark-green line that goes from (1.71*0.4, 0.4*(1.71^3)) to (-1.71*0.4,0.4*(-1.71^3))?
– Hans
7 hours ago
@Hans See my answer, I have removed the slight line with a different filling technique.
– quark67
3 hours ago
add a comment |
Here is my suggestion, without slightly line, because the filling is made differently (code modified from AndréC answer):
documentclass[tikz,border=5mm]{standalone}
begin{document}
begin{tikzpicture}
begin{scope}
clip[postaction={fill=green!50}] (-2,-2) rectangle (2,2);
fill[scale=0.4,domain=0:5,smooth,variable=x,blue!20] plot ({x},{(x)^3}) |-(0,0);
fill[scale=0.4,domain=0:-5,smooth,variable=x,blue!20] plot ({x},{(x)^3}) |-(0,0);
draw[scale=0.4,domain=-1.71:1.71,smooth,variable=x,black] plot ({x},{(x)^3});
end{scope}
draw[->] (-2,0) -- (2,0) node[right] {$x$};
draw[->] (0,-2) -- (0,2) node[above] {$y$};
end{tikzpicture}
end{document}
(Code edited with marmot's useful suggestion: using postaction
to reduce redundant code.)
1
@marmot Thanks, I have edited with your great advice.
– quark67
2 hours ago
add a comment |
With pgfplots
, this is easy to do.
Here is a pure tikz
DIY without a single piece of pgfplots!
documentclass[tikz,border=5mm]{standalone}
begin{document}
begin{tikzpicture}
fill[blue!20] (-2,-2)rectangle(2,2);
begin{scope}[transparency group,opacity=.9]
fill[scale=0.4,domain=0:1.71,smooth,variable=x,green] plot ({x},{(x)^3})coordinate(a)|-(0,0)node[midway](m){};
fill[green](a)--(2,2)|-(m.center);
fill[scale=0.4,domain=0:-1.71,smooth,variable=x,green] plot ({x},{(x)^3})coordinate(b)|-(0,0)node[midway](n){};
fill[green](b)--(-2,-2)|-(n.center);
end{scope}
draw[scale=0.4,domain=-1.71:1.71,smooth,variable=x,black] plot ({x},{(x)^3});
draw[->] (-2,0) -- (2,0) node[right] {$x$};
draw[->] (0,-2) -- (0,2) node[above] {$y$};
end{tikzpicture}
end{document}
There is a slight vertical line in your screenshot (at x=-1.71) because you fill this lower left domain with 2 areas (there is also a slight vertical line at x=+1.71 in the upper right domain, but not visible in your screenshot).
– quark67
3 hours ago
You have a much better view than I do. I have just created atransparency group
, normally this little net should have disappeared.
– AndréC
2 hours ago
add a comment |
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
});
}
});
Hans is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f476980%2fi-want-to-color-a-graph%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
A tricky way:
documentclass[tikz,margin=3mm]{standalone}
begin{document}
begin{tikzpicture}
fill[blue!20] (-2,-2) rectangle (2,2);
fill[green!50] (0,0)--({-1.71*0.4},{0.4*(-1.71^3)})--(2,-2)--(2,0)--cycle;
fill[green!50] (0,0)--({1.71*0.4},{0.4*(1.71^3)})--(-2,2)--(-2,0)--cycle;
draw[->] (-2,0) -- (2,0) node[right] {$x$};
draw[->] (0,-2) -- (0,2) node[above] {$y$};
draw[scale=0.4,domain=-1.71:1.71,smooth,variable=x,black,fill=green!50] plot ({x},{(x)^3});
end{tikzpicture}
end{document}
We see a line that joins the two ends of the curve.
– AndréC
8 hours ago
That looks exactly like i want it! But is there any way to get around that slightly visible dark-green line that goes from (1.71*0.4, 0.4*(1.71^3)) to (-1.71*0.4,0.4*(-1.71^3))?
– Hans
7 hours ago
@Hans See my answer, I have removed the slight line with a different filling technique.
– quark67
3 hours ago
add a comment |
A tricky way:
documentclass[tikz,margin=3mm]{standalone}
begin{document}
begin{tikzpicture}
fill[blue!20] (-2,-2) rectangle (2,2);
fill[green!50] (0,0)--({-1.71*0.4},{0.4*(-1.71^3)})--(2,-2)--(2,0)--cycle;
fill[green!50] (0,0)--({1.71*0.4},{0.4*(1.71^3)})--(-2,2)--(-2,0)--cycle;
draw[->] (-2,0) -- (2,0) node[right] {$x$};
draw[->] (0,-2) -- (0,2) node[above] {$y$};
draw[scale=0.4,domain=-1.71:1.71,smooth,variable=x,black,fill=green!50] plot ({x},{(x)^3});
end{tikzpicture}
end{document}
We see a line that joins the two ends of the curve.
– AndréC
8 hours ago
That looks exactly like i want it! But is there any way to get around that slightly visible dark-green line that goes from (1.71*0.4, 0.4*(1.71^3)) to (-1.71*0.4,0.4*(-1.71^3))?
– Hans
7 hours ago
@Hans See my answer, I have removed the slight line with a different filling technique.
– quark67
3 hours ago
add a comment |
A tricky way:
documentclass[tikz,margin=3mm]{standalone}
begin{document}
begin{tikzpicture}
fill[blue!20] (-2,-2) rectangle (2,2);
fill[green!50] (0,0)--({-1.71*0.4},{0.4*(-1.71^3)})--(2,-2)--(2,0)--cycle;
fill[green!50] (0,0)--({1.71*0.4},{0.4*(1.71^3)})--(-2,2)--(-2,0)--cycle;
draw[->] (-2,0) -- (2,0) node[right] {$x$};
draw[->] (0,-2) -- (0,2) node[above] {$y$};
draw[scale=0.4,domain=-1.71:1.71,smooth,variable=x,black,fill=green!50] plot ({x},{(x)^3});
end{tikzpicture}
end{document}
A tricky way:
documentclass[tikz,margin=3mm]{standalone}
begin{document}
begin{tikzpicture}
fill[blue!20] (-2,-2) rectangle (2,2);
fill[green!50] (0,0)--({-1.71*0.4},{0.4*(-1.71^3)})--(2,-2)--(2,0)--cycle;
fill[green!50] (0,0)--({1.71*0.4},{0.4*(1.71^3)})--(-2,2)--(-2,0)--cycle;
draw[->] (-2,0) -- (2,0) node[right] {$x$};
draw[->] (0,-2) -- (0,2) node[above] {$y$};
draw[scale=0.4,domain=-1.71:1.71,smooth,variable=x,black,fill=green!50] plot ({x},{(x)^3});
end{tikzpicture}
end{document}
answered 8 hours ago
JouleVJouleV
4,3251938
4,3251938
We see a line that joins the two ends of the curve.
– AndréC
8 hours ago
That looks exactly like i want it! But is there any way to get around that slightly visible dark-green line that goes from (1.71*0.4, 0.4*(1.71^3)) to (-1.71*0.4,0.4*(-1.71^3))?
– Hans
7 hours ago
@Hans See my answer, I have removed the slight line with a different filling technique.
– quark67
3 hours ago
add a comment |
We see a line that joins the two ends of the curve.
– AndréC
8 hours ago
That looks exactly like i want it! But is there any way to get around that slightly visible dark-green line that goes from (1.71*0.4, 0.4*(1.71^3)) to (-1.71*0.4,0.4*(-1.71^3))?
– Hans
7 hours ago
@Hans See my answer, I have removed the slight line with a different filling technique.
– quark67
3 hours ago
We see a line that joins the two ends of the curve.
– AndréC
8 hours ago
We see a line that joins the two ends of the curve.
– AndréC
8 hours ago
That looks exactly like i want it! But is there any way to get around that slightly visible dark-green line that goes from (1.71*0.4, 0.4*(1.71^3)) to (-1.71*0.4,0.4*(-1.71^3))?
– Hans
7 hours ago
That looks exactly like i want it! But is there any way to get around that slightly visible dark-green line that goes from (1.71*0.4, 0.4*(1.71^3)) to (-1.71*0.4,0.4*(-1.71^3))?
– Hans
7 hours ago
@Hans See my answer, I have removed the slight line with a different filling technique.
– quark67
3 hours ago
@Hans See my answer, I have removed the slight line with a different filling technique.
– quark67
3 hours ago
add a comment |
Here is my suggestion, without slightly line, because the filling is made differently (code modified from AndréC answer):
documentclass[tikz,border=5mm]{standalone}
begin{document}
begin{tikzpicture}
begin{scope}
clip[postaction={fill=green!50}] (-2,-2) rectangle (2,2);
fill[scale=0.4,domain=0:5,smooth,variable=x,blue!20] plot ({x},{(x)^3}) |-(0,0);
fill[scale=0.4,domain=0:-5,smooth,variable=x,blue!20] plot ({x},{(x)^3}) |-(0,0);
draw[scale=0.4,domain=-1.71:1.71,smooth,variable=x,black] plot ({x},{(x)^3});
end{scope}
draw[->] (-2,0) -- (2,0) node[right] {$x$};
draw[->] (0,-2) -- (0,2) node[above] {$y$};
end{tikzpicture}
end{document}
(Code edited with marmot's useful suggestion: using postaction
to reduce redundant code.)
1
@marmot Thanks, I have edited with your great advice.
– quark67
2 hours ago
add a comment |
Here is my suggestion, without slightly line, because the filling is made differently (code modified from AndréC answer):
documentclass[tikz,border=5mm]{standalone}
begin{document}
begin{tikzpicture}
begin{scope}
clip[postaction={fill=green!50}] (-2,-2) rectangle (2,2);
fill[scale=0.4,domain=0:5,smooth,variable=x,blue!20] plot ({x},{(x)^3}) |-(0,0);
fill[scale=0.4,domain=0:-5,smooth,variable=x,blue!20] plot ({x},{(x)^3}) |-(0,0);
draw[scale=0.4,domain=-1.71:1.71,smooth,variable=x,black] plot ({x},{(x)^3});
end{scope}
draw[->] (-2,0) -- (2,0) node[right] {$x$};
draw[->] (0,-2) -- (0,2) node[above] {$y$};
end{tikzpicture}
end{document}
(Code edited with marmot's useful suggestion: using postaction
to reduce redundant code.)
1
@marmot Thanks, I have edited with your great advice.
– quark67
2 hours ago
add a comment |
Here is my suggestion, without slightly line, because the filling is made differently (code modified from AndréC answer):
documentclass[tikz,border=5mm]{standalone}
begin{document}
begin{tikzpicture}
begin{scope}
clip[postaction={fill=green!50}] (-2,-2) rectangle (2,2);
fill[scale=0.4,domain=0:5,smooth,variable=x,blue!20] plot ({x},{(x)^3}) |-(0,0);
fill[scale=0.4,domain=0:-5,smooth,variable=x,blue!20] plot ({x},{(x)^3}) |-(0,0);
draw[scale=0.4,domain=-1.71:1.71,smooth,variable=x,black] plot ({x},{(x)^3});
end{scope}
draw[->] (-2,0) -- (2,0) node[right] {$x$};
draw[->] (0,-2) -- (0,2) node[above] {$y$};
end{tikzpicture}
end{document}
(Code edited with marmot's useful suggestion: using postaction
to reduce redundant code.)
Here is my suggestion, without slightly line, because the filling is made differently (code modified from AndréC answer):
documentclass[tikz,border=5mm]{standalone}
begin{document}
begin{tikzpicture}
begin{scope}
clip[postaction={fill=green!50}] (-2,-2) rectangle (2,2);
fill[scale=0.4,domain=0:5,smooth,variable=x,blue!20] plot ({x},{(x)^3}) |-(0,0);
fill[scale=0.4,domain=0:-5,smooth,variable=x,blue!20] plot ({x},{(x)^3}) |-(0,0);
draw[scale=0.4,domain=-1.71:1.71,smooth,variable=x,black] plot ({x},{(x)^3});
end{scope}
draw[->] (-2,0) -- (2,0) node[right] {$x$};
draw[->] (0,-2) -- (0,2) node[above] {$y$};
end{tikzpicture}
end{document}
(Code edited with marmot's useful suggestion: using postaction
to reduce redundant code.)
edited 2 hours ago
answered 3 hours ago
quark67quark67
16915
16915
1
@marmot Thanks, I have edited with your great advice.
– quark67
2 hours ago
add a comment |
1
@marmot Thanks, I have edited with your great advice.
– quark67
2 hours ago
1
1
@marmot Thanks, I have edited with your great advice.
– quark67
2 hours ago
@marmot Thanks, I have edited with your great advice.
– quark67
2 hours ago
add a comment |
With pgfplots
, this is easy to do.
Here is a pure tikz
DIY without a single piece of pgfplots!
documentclass[tikz,border=5mm]{standalone}
begin{document}
begin{tikzpicture}
fill[blue!20] (-2,-2)rectangle(2,2);
begin{scope}[transparency group,opacity=.9]
fill[scale=0.4,domain=0:1.71,smooth,variable=x,green] plot ({x},{(x)^3})coordinate(a)|-(0,0)node[midway](m){};
fill[green](a)--(2,2)|-(m.center);
fill[scale=0.4,domain=0:-1.71,smooth,variable=x,green] plot ({x},{(x)^3})coordinate(b)|-(0,0)node[midway](n){};
fill[green](b)--(-2,-2)|-(n.center);
end{scope}
draw[scale=0.4,domain=-1.71:1.71,smooth,variable=x,black] plot ({x},{(x)^3});
draw[->] (-2,0) -- (2,0) node[right] {$x$};
draw[->] (0,-2) -- (0,2) node[above] {$y$};
end{tikzpicture}
end{document}
There is a slight vertical line in your screenshot (at x=-1.71) because you fill this lower left domain with 2 areas (there is also a slight vertical line at x=+1.71 in the upper right domain, but not visible in your screenshot).
– quark67
3 hours ago
You have a much better view than I do. I have just created atransparency group
, normally this little net should have disappeared.
– AndréC
2 hours ago
add a comment |
With pgfplots
, this is easy to do.
Here is a pure tikz
DIY without a single piece of pgfplots!
documentclass[tikz,border=5mm]{standalone}
begin{document}
begin{tikzpicture}
fill[blue!20] (-2,-2)rectangle(2,2);
begin{scope}[transparency group,opacity=.9]
fill[scale=0.4,domain=0:1.71,smooth,variable=x,green] plot ({x},{(x)^3})coordinate(a)|-(0,0)node[midway](m){};
fill[green](a)--(2,2)|-(m.center);
fill[scale=0.4,domain=0:-1.71,smooth,variable=x,green] plot ({x},{(x)^3})coordinate(b)|-(0,0)node[midway](n){};
fill[green](b)--(-2,-2)|-(n.center);
end{scope}
draw[scale=0.4,domain=-1.71:1.71,smooth,variable=x,black] plot ({x},{(x)^3});
draw[->] (-2,0) -- (2,0) node[right] {$x$};
draw[->] (0,-2) -- (0,2) node[above] {$y$};
end{tikzpicture}
end{document}
There is a slight vertical line in your screenshot (at x=-1.71) because you fill this lower left domain with 2 areas (there is also a slight vertical line at x=+1.71 in the upper right domain, but not visible in your screenshot).
– quark67
3 hours ago
You have a much better view than I do. I have just created atransparency group
, normally this little net should have disappeared.
– AndréC
2 hours ago
add a comment |
With pgfplots
, this is easy to do.
Here is a pure tikz
DIY without a single piece of pgfplots!
documentclass[tikz,border=5mm]{standalone}
begin{document}
begin{tikzpicture}
fill[blue!20] (-2,-2)rectangle(2,2);
begin{scope}[transparency group,opacity=.9]
fill[scale=0.4,domain=0:1.71,smooth,variable=x,green] plot ({x},{(x)^3})coordinate(a)|-(0,0)node[midway](m){};
fill[green](a)--(2,2)|-(m.center);
fill[scale=0.4,domain=0:-1.71,smooth,variable=x,green] plot ({x},{(x)^3})coordinate(b)|-(0,0)node[midway](n){};
fill[green](b)--(-2,-2)|-(n.center);
end{scope}
draw[scale=0.4,domain=-1.71:1.71,smooth,variable=x,black] plot ({x},{(x)^3});
draw[->] (-2,0) -- (2,0) node[right] {$x$};
draw[->] (0,-2) -- (0,2) node[above] {$y$};
end{tikzpicture}
end{document}
With pgfplots
, this is easy to do.
Here is a pure tikz
DIY without a single piece of pgfplots!
documentclass[tikz,border=5mm]{standalone}
begin{document}
begin{tikzpicture}
fill[blue!20] (-2,-2)rectangle(2,2);
begin{scope}[transparency group,opacity=.9]
fill[scale=0.4,domain=0:1.71,smooth,variable=x,green] plot ({x},{(x)^3})coordinate(a)|-(0,0)node[midway](m){};
fill[green](a)--(2,2)|-(m.center);
fill[scale=0.4,domain=0:-1.71,smooth,variable=x,green] plot ({x},{(x)^3})coordinate(b)|-(0,0)node[midway](n){};
fill[green](b)--(-2,-2)|-(n.center);
end{scope}
draw[scale=0.4,domain=-1.71:1.71,smooth,variable=x,black] plot ({x},{(x)^3});
draw[->] (-2,0) -- (2,0) node[right] {$x$};
draw[->] (0,-2) -- (0,2) node[above] {$y$};
end{tikzpicture}
end{document}
edited 2 hours ago
answered 7 hours ago
AndréCAndréC
9,44111447
9,44111447
There is a slight vertical line in your screenshot (at x=-1.71) because you fill this lower left domain with 2 areas (there is also a slight vertical line at x=+1.71 in the upper right domain, but not visible in your screenshot).
– quark67
3 hours ago
You have a much better view than I do. I have just created atransparency group
, normally this little net should have disappeared.
– AndréC
2 hours ago
add a comment |
There is a slight vertical line in your screenshot (at x=-1.71) because you fill this lower left domain with 2 areas (there is also a slight vertical line at x=+1.71 in the upper right domain, but not visible in your screenshot).
– quark67
3 hours ago
You have a much better view than I do. I have just created atransparency group
, normally this little net should have disappeared.
– AndréC
2 hours ago
There is a slight vertical line in your screenshot (at x=-1.71) because you fill this lower left domain with 2 areas (there is also a slight vertical line at x=+1.71 in the upper right domain, but not visible in your screenshot).
– quark67
3 hours ago
There is a slight vertical line in your screenshot (at x=-1.71) because you fill this lower left domain with 2 areas (there is also a slight vertical line at x=+1.71 in the upper right domain, but not visible in your screenshot).
– quark67
3 hours ago
You have a much better view than I do. I have just created a
transparency group
, normally this little net should have disappeared.– AndréC
2 hours ago
You have a much better view than I do. I have just created a
transparency group
, normally this little net should have disappeared.– AndréC
2 hours ago
add a comment |
Hans is a new contributor. Be nice, and check out our Code of Conduct.
Hans is a new contributor. Be nice, and check out our Code of Conduct.
Hans is a new contributor. Be nice, and check out our Code of Conduct.
Hans is a new contributor. Be nice, and check out our Code of Conduct.
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f476980%2fi-want-to-color-a-graph%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
1
(written without compiling)
fill [green] (-2,0) plot [domain=0:1.26] (x,x^3) |- cycle;
– Symbol 1
9 hours ago
Oh i didnt know it was that easy! It looks good, but because of the scale=0.4, the green area isnt correctly under the graph. How to i re-scale the green area?
– Hans
8 hours ago
I figured it out! i just added it in the square brackets:
fill [green, scale=0.4] (-2,2) plot [domain=0:0.5] (x,x^3) |- cycle;
– Hans
8 hours ago
But how do I color even farther out to the right like I drew on the paper? And how to color the other four areas?
– Hans
8 hours ago
Either you specify coordinates carefully (e.g.
1.26
in my code in cubic root of2
) or useclip
– Symbol 1
8 hours ago