I want to color a graphTikZ: draw line thickness less than 0.1 mmLaTeX equivalent of ConTeXt buffersVisualize...
Do my Windows system binaries contain sensitive information?
What's the rationale behind the objections to these measures against human trafficking?
Quenching swords in dragon blood; why?
Proof by Induction - New to proofs
Why zero tolerance on nudity in space?
Is Draco canonically good-looking?
Could quantum mechanics be necessary to analyze some biology scenarios?
Criticizing long fiction. How is it different from short?
Has the Isbell–Freyd criterion ever been used to check that a category is concretisable?
What is Crew Dragon approaching in this picture?
A Wacky, Wacky Chessboard (That Makes No Sense)
Do commercial flights continue with an engine out?
Is my plan for fixing my water heater leak bad?
Can chords be played on the flute?
Can the Count of Monte Cristo's calculation of poison dosage be explained?
Is the theory of the category of topological spaces computable?
How to use a mathematical expression as xticklable
How would one communicate with the hive mind of the human race?
Meth dealer reference in Family Guy
What can I substitute for soda pop in a sweet pork recipe?
How to define a macro with multiple optional parameters?
On what did Lego base the appearance of the new Hogwarts minifigs?
Do authors have to be politically correct in article-writing?
raspberry pi change directory (cd) command not working with USB drive
I want to color a graph
TikZ: draw line thickness less than 0.1 mmLaTeX 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
Feb 27 at 15:53
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
Feb 27 at 16:10
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
Feb 27 at 16:12
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
Feb 27 at 16:21
Either you specify coordinates carefully (e.g.1.26
in my code in cubic root of2
) or useclip
– Symbol 1
Feb 27 at 16:23
|
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 Feb 27 at 15:50
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
Feb 27 at 15:53
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
Feb 27 at 16:10
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
Feb 27 at 16:12
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
Feb 27 at 16:21
Either you specify coordinates carefully (e.g.1.26
in my code in cubic root of2
) or useclip
– Symbol 1
Feb 27 at 16:23
|
show 1 more comment
1
(written without compiling)fill [green] (-2,0) plot [domain=0:1.26] (x,x^3) |- cycle;
– Symbol 1
Feb 27 at 15:53
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
Feb 27 at 16:10
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
Feb 27 at 16:12
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
Feb 27 at 16:21
Either you specify coordinates carefully (e.g.1.26
in my code in cubic root of2
) or useclip
– Symbol 1
Feb 27 at 16:23
1
1
(written without compiling)
fill [green] (-2,0) plot [domain=0:1.26] (x,x^3) |- cycle;
– Symbol 1
Feb 27 at 15:53
(written without compiling)
fill [green] (-2,0) plot [domain=0:1.26] (x,x^3) |- cycle;
– Symbol 1
Feb 27 at 15:53
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
Feb 27 at 16:10
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
Feb 27 at 16:10
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
Feb 27 at 16:12
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
Feb 27 at 16:12
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
Feb 27 at 16:21
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
Feb 27 at 16:21
Either you specify coordinates carefully (e.g.
1.26
in my code in cubic root of 2
) or use clip
– Symbol 1
Feb 27 at 16:23
Either you specify coordinates carefully (e.g.
1.26
in my code in cubic root of 2
) or use clip
– Symbol 1
Feb 27 at 16:23
|
show 1 more comment
3 Answers
3
active
oldest
votes
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
Feb 27 at 22:50
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}
Edit:
A tricky way needs to be continued by a tricky addition. I added a line width=0mm
line (see here):
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[line width=0mm,green!50] ({1.71*0.4},{0.4*(1.71^3)})--({-1.71*0.4},{0.4*(-1.71^3)}); % <===================
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}
The very thin line has gone I think.
We see a line that joins the two ends of the curve.
– AndréC
Feb 27 at 17:00
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
Feb 27 at 17:01
@Hans See my answer, I have removed the slight line with a different filling technique.
– quark67
Feb 27 at 21:37
@Hans I have edited my answer. (I'm sorry for being late).
– JouleV
Feb 28 at 4:08
By the way, as my solution is not standard, it doesn't deserve a tick. Accept quark67's answer instead.
– JouleV
Feb 28 at 4:11
|
show 2 more comments
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=1]
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.west);
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.east);
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
Feb 27 at 21:22
You have a much better view than I do. I have just created atransparency group
, normally this little net should have disappeared.
– AndréC
Feb 27 at 22:19
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
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
Feb 27 at 22:50
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
Feb 27 at 22:50
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 Feb 27 at 22:49
answered Feb 27 at 21:30
quark67quark67
19415
19415
1
@marmot Thanks, I have edited with your great advice.
– quark67
Feb 27 at 22:50
add a comment |
1
@marmot Thanks, I have edited with your great advice.
– quark67
Feb 27 at 22:50
1
1
@marmot Thanks, I have edited with your great advice.
– quark67
Feb 27 at 22:50
@marmot Thanks, I have edited with your great advice.
– quark67
Feb 27 at 22:50
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}
Edit:
A tricky way needs to be continued by a tricky addition. I added a line width=0mm
line (see here):
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[line width=0mm,green!50] ({1.71*0.4},{0.4*(1.71^3)})--({-1.71*0.4},{0.4*(-1.71^3)}); % <===================
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}
The very thin line has gone I think.
We see a line that joins the two ends of the curve.
– AndréC
Feb 27 at 17:00
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
Feb 27 at 17:01
@Hans See my answer, I have removed the slight line with a different filling technique.
– quark67
Feb 27 at 21:37
@Hans I have edited my answer. (I'm sorry for being late).
– JouleV
Feb 28 at 4:08
By the way, as my solution is not standard, it doesn't deserve a tick. Accept quark67's answer instead.
– JouleV
Feb 28 at 4:11
|
show 2 more comments
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}
Edit:
A tricky way needs to be continued by a tricky addition. I added a line width=0mm
line (see here):
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[line width=0mm,green!50] ({1.71*0.4},{0.4*(1.71^3)})--({-1.71*0.4},{0.4*(-1.71^3)}); % <===================
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}
The very thin line has gone I think.
We see a line that joins the two ends of the curve.
– AndréC
Feb 27 at 17:00
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
Feb 27 at 17:01
@Hans See my answer, I have removed the slight line with a different filling technique.
– quark67
Feb 27 at 21:37
@Hans I have edited my answer. (I'm sorry for being late).
– JouleV
Feb 28 at 4:08
By the way, as my solution is not standard, it doesn't deserve a tick. Accept quark67's answer instead.
– JouleV
Feb 28 at 4:11
|
show 2 more comments
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}
Edit:
A tricky way needs to be continued by a tricky addition. I added a line width=0mm
line (see here):
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[line width=0mm,green!50] ({1.71*0.4},{0.4*(1.71^3)})--({-1.71*0.4},{0.4*(-1.71^3)}); % <===================
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}
The very thin line has gone I think.
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}
Edit:
A tricky way needs to be continued by a tricky addition. I added a line width=0mm
line (see here):
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[line width=0mm,green!50] ({1.71*0.4},{0.4*(1.71^3)})--({-1.71*0.4},{0.4*(-1.71^3)}); % <===================
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}
The very thin line has gone I think.
edited Feb 28 at 4:08
answered Feb 27 at 16:27
JouleVJouleV
4,6861939
4,6861939
We see a line that joins the two ends of the curve.
– AndréC
Feb 27 at 17:00
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
Feb 27 at 17:01
@Hans See my answer, I have removed the slight line with a different filling technique.
– quark67
Feb 27 at 21:37
@Hans I have edited my answer. (I'm sorry for being late).
– JouleV
Feb 28 at 4:08
By the way, as my solution is not standard, it doesn't deserve a tick. Accept quark67's answer instead.
– JouleV
Feb 28 at 4:11
|
show 2 more comments
We see a line that joins the two ends of the curve.
– AndréC
Feb 27 at 17:00
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
Feb 27 at 17:01
@Hans See my answer, I have removed the slight line with a different filling technique.
– quark67
Feb 27 at 21:37
@Hans I have edited my answer. (I'm sorry for being late).
– JouleV
Feb 28 at 4:08
By the way, as my solution is not standard, it doesn't deserve a tick. Accept quark67's answer instead.
– JouleV
Feb 28 at 4:11
We see a line that joins the two ends of the curve.
– AndréC
Feb 27 at 17:00
We see a line that joins the two ends of the curve.
– AndréC
Feb 27 at 17:00
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
Feb 27 at 17:01
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
Feb 27 at 17:01
@Hans See my answer, I have removed the slight line with a different filling technique.
– quark67
Feb 27 at 21:37
@Hans See my answer, I have removed the slight line with a different filling technique.
– quark67
Feb 27 at 21:37
@Hans I have edited my answer. (I'm sorry for being late).
– JouleV
Feb 28 at 4:08
@Hans I have edited my answer. (I'm sorry for being late).
– JouleV
Feb 28 at 4:08
By the way, as my solution is not standard, it doesn't deserve a tick. Accept quark67's answer instead.
– JouleV
Feb 28 at 4:11
By the way, as my solution is not standard, it doesn't deserve a tick. Accept quark67's answer instead.
– JouleV
Feb 28 at 4:11
|
show 2 more comments
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=1]
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.west);
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.east);
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
Feb 27 at 21:22
You have a much better view than I do. I have just created atransparency group
, normally this little net should have disappeared.
– AndréC
Feb 27 at 22:19
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=1]
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.west);
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.east);
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
Feb 27 at 21:22
You have a much better view than I do. I have just created atransparency group
, normally this little net should have disappeared.
– AndréC
Feb 27 at 22:19
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=1]
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.west);
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.east);
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=1]
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.west);
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.east);
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 Feb 28 at 6:02
answered Feb 27 at 17:55
AndréCAndréC
9,52311547
9,52311547
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
Feb 27 at 21:22
You have a much better view than I do. I have just created atransparency group
, normally this little net should have disappeared.
– AndréC
Feb 27 at 22:19
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
Feb 27 at 21:22
You have a much better view than I do. I have just created atransparency group
, normally this little net should have disappeared.
– AndréC
Feb 27 at 22:19
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
Feb 27 at 21:22
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
Feb 27 at 21:22
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
Feb 27 at 22:19
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
Feb 27 at 22:19
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
Feb 27 at 15:53
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
Feb 27 at 16:10
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
Feb 27 at 16:12
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
Feb 27 at 16:21
Either you specify coordinates carefully (e.g.
1.26
in my code in cubic root of2
) or useclip
– Symbol 1
Feb 27 at 16:23