I want to color a graphLaTeX equivalent of ConTeXt buffersVisualize data on a variable-radius...
Numbers with a minus sign in a matrix not aligned with the numbers wihtout minus sign
Dilemma of explaining to interviewer that he is the reason for declining second interview
How can I get my players to come to the game session after agreeing to a date?
Why publish a research paper when a blog post or a lecture slide can have more citation count than a journal paper?
False written accusations not made public - is there law to cover this?
How to deal with an incendiary email that was recalled
How would an AI self awareness kill switch work?
Why am I able to open Wireshark in macOS without root privileges?
Can my spouse sponsor me for a UK visa if I am unemployed?
Gear reduction on large turbofans
Is using an 'empty' metaphor considered bad style?
Do authors have to be politically correct in article-writing?
How does Leonard in "Memento" remember reading and writing?
Why is Agricola named as such?
How old is the day of 24 equal hours?
It took me a lot of time to make this, pls like. (YouTube Comments #1)
Odd 74HCT1G125 behaviour
Making him into a bully (how to show mild violence)
How can my powered armor quickly replace its ceramic plates?
Words and Words with "ver-" Prefix
Why is it that Bernie Sanders is always called a "socialist"?
What is the data structure of $@ in shell?
How do you funnel food off a cutting board?
How should I handle players who ignore the session zero agreement?
I want to color a graph
LaTeX equivalent of ConTeXt buffersVisualize data on a variable-radius graph/networkColor the faces of a graphTikZ scaling graphic and adjust node position and keep font sizeGraph functions & color area under curvesLine up nested tikz enviroments or how to get rid of themProblems with nested TikZpicturesHighlighting and Labeling specific nodes in scatter plotThe TikZ pipeline: A path's 'draw' option has no effect on a 'behind path' nodeDrawing an imperfect spiral in TikZ
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
7 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
7 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
7 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
7 hours ago
Either you specify coordinates carefully (e.g.1.26
in my code in cubic root of2
) or useclip
– Symbol 1
7 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 7 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
7 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
7 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
7 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
7 hours ago
Either you specify coordinates carefully (e.g.1.26
in my code in cubic root of2
) or useclip
– Symbol 1
7 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
7 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
7 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
7 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
7 hours ago
Either you specify coordinates carefully (e.g.1.26
in my code in cubic root of2
) or useclip
– Symbol 1
7 hours ago
1
1
(written without compiling)
fill [green] (-2,0) plot [domain=0:1.26] (x,x^3) |- cycle;
– Symbol 1
7 hours ago
(written without compiling)
fill [green] (-2,0) plot [domain=0:1.26] (x,x^3) |- cycle;
– Symbol 1
7 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
7 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
7 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
7 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
7 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
7 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
7 hours ago
Either you specify coordinates carefully (e.g.
1.26
in my code in cubic root of 2
) or use clip
– Symbol 1
7 hours ago
Either you specify coordinates carefully (e.g.
1.26
in my code in cubic root of 2
) or use clip
– Symbol 1
7 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
6 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
6 hours ago
@Hans See my answer, I have removed the slight line with a different filling technique.
– 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
51 mins 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
2 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
1 hour 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
6 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
6 hours ago
@Hans See my answer, I have removed the slight line with a different filling technique.
– quark67
2 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
6 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
6 hours ago
@Hans See my answer, I have removed the slight line with a different filling technique.
– quark67
2 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 7 hours ago
JouleVJouleV
4,3251938
4,3251938
We see a line that joins the two ends of the curve.
– AndréC
6 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
6 hours ago
@Hans See my answer, I have removed the slight line with a different filling technique.
– quark67
2 hours ago
add a comment |
We see a line that joins the two ends of the curve.
– AndréC
6 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
6 hours ago
@Hans See my answer, I have removed the slight line with a different filling technique.
– quark67
2 hours ago
We see a line that joins the two ends of the curve.
– AndréC
6 hours ago
We see a line that joins the two ends of the curve.
– AndréC
6 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
6 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
6 hours ago
@Hans See my answer, I have removed the slight line with a different filling technique.
– quark67
2 hours ago
@Hans See my answer, I have removed the slight line with a different filling technique.
– 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
51 mins 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
51 mins 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 52 mins ago
answered 2 hours ago
quark67quark67
16915
16915
1
@marmot Thanks, I have edited with your great advice.
– quark67
51 mins ago
add a comment |
1
@marmot Thanks, I have edited with your great advice.
– quark67
51 mins ago
1
1
@marmot Thanks, I have edited with your great advice.
– quark67
51 mins ago
@marmot Thanks, I have edited with your great advice.
– quark67
51 mins 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
2 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
1 hour 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
2 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
1 hour 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 1 hour ago
answered 5 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
2 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
1 hour 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
2 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
1 hour 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
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
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
1 hour 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
1 hour 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
7 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
7 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
7 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
7 hours ago
Either you specify coordinates carefully (e.g.
1.26
in my code in cubic root of2
) or useclip
– Symbol 1
7 hours ago