Find a good view for a function by parts using tikzpicture environmentDrawing multiple double headed...
Why would space fleets be aligned?
Potential client has a problematic employee I can't work with
Best way to strengthen a wheel?
How much mayhem could I cause as a fish?
Count repetitions of an array
What is the difference between rolling more dice versus fewer dice?
How can the probability of a fumble decrease linearly with more dice?
Prioritising polygons in QGIS
Saint abbreviation
What makes papers publishable in top-tier journals?
Does diversity provide anything that meritocracy does not?
Do authors have to be politically correct in article-writing?
What is the wife of a henpecked husband called?
Non-Cancer terminal illness that can affect young (age 10-13) girls?
In Linux what happens if 1000 files in a directory are moved to another location while another 300 files were added to the source directory?
How to deal with possible delayed baggage?
What will happen if I transfer large sums of money into my bank account from a pre-paid debit card or gift card?
microtype error with lualatex: "attempt to call field warning a nil value"
How would an AI self awareness kill switch work?
Early credit roll before the end of the film
Why did the villain in the first Men in Black movie care about Earth's Cockroaches?
Changing the laptop's CPU. Should I reinstall Linux?
What will happen if Parliament votes "no" on each of the Brexit-related votes to be held on the 12th, 13th and 14th of March?
Is a new boolean field better than null reference when a value can be meaningfully absent?
Find a good view for a function by parts using tikzpicture environment
Drawing multiple double headed arrowsDrawing a parametric line with unitary director vector produces a longer straight line using `PGFPlots`Using caption for tikzpictureDeclare function for tikzpictureTikzpicture e-functionHow to prevent rounded and duplicated tick labels in pgfplots with fixed precision?tikzpicture negative gamma functionTikzpicture - 3D Polyhedron - find points for linesTikzpicture: Steplike functionDraw an ellipse into two parts using tikzpicture environmentHow to divide a circle into 3 parts with text using tikzpicture environmentcreate a standalone legend for a grid of plots
I want to plot sqrt(-xy) if xy<=0, and -x^2+y if xy>0.
Please consider this MWE:
documentclass{article}
usepackage[utf8]{inputenc}
usepackage{pgfplots}
pgfplotsset{compat=1.8}
pgfplotsset{soldot/.style={color=black,only marks,mark=*}}
pgfplotsset{holdot/.style={color=red,fill=white,very thick,only marks,mark=*}}
begin{document}
begin{center}
begin{tikzpicture}[scale=2]
begin{axis}[
legend pos=outer north east,
axis lines = center,
view={-35}{15},
xticklabel style = {font=tiny},
yticklabel style = {font=tiny},
zticklabel style = {font=tiny},
xlabel = $x$,
ylabel = $y$,
zlabel = $z$,
legend style={cells={align=left}}
]
addplot3[surf,mesh/ordering=y varies,shader=interp,domain=-3:0,domain y=0:3,samples=40, samples y=20] {sqrt(-x*y)};
addplot3[surf,mesh/ordering=y varies,shader=interp,domain=0:3,domain y=0:-3,samples=40, samples y=20] {sqrt(-x*y)};
addplot3[surf,mesh/ordering=y varies,shader=interp,domain=0:3,domain y=0:3,samples=40, samples y=20] {-x*x+y};
addplot3[surf,mesh/ordering=y varies,shader=interp,domain=-3:0,domain y=0:-3,samples=40, samples y=20] {-x*x+y};
end{axis}
end{tikzpicture}
end{center}
end{document}

I cannot find a good view for display the function. I think I like the view from the x<0 and y<0 but it is the image and it is ugly. What do you recommend not using gnuplot?
Thanks!
EDIT. I also would like to graph 7 vectors with norm 1: 4 in the xy-plane, and 3 in the direction of x>0 and y>0. i.e.:

in 3D. If it is complicated to see, you can do it in 2D, like the image.
tikz-pgf
add a comment |
I want to plot sqrt(-xy) if xy<=0, and -x^2+y if xy>0.
Please consider this MWE:
documentclass{article}
usepackage[utf8]{inputenc}
usepackage{pgfplots}
pgfplotsset{compat=1.8}
pgfplotsset{soldot/.style={color=black,only marks,mark=*}}
pgfplotsset{holdot/.style={color=red,fill=white,very thick,only marks,mark=*}}
begin{document}
begin{center}
begin{tikzpicture}[scale=2]
begin{axis}[
legend pos=outer north east,
axis lines = center,
view={-35}{15},
xticklabel style = {font=tiny},
yticklabel style = {font=tiny},
zticklabel style = {font=tiny},
xlabel = $x$,
ylabel = $y$,
zlabel = $z$,
legend style={cells={align=left}}
]
addplot3[surf,mesh/ordering=y varies,shader=interp,domain=-3:0,domain y=0:3,samples=40, samples y=20] {sqrt(-x*y)};
addplot3[surf,mesh/ordering=y varies,shader=interp,domain=0:3,domain y=0:-3,samples=40, samples y=20] {sqrt(-x*y)};
addplot3[surf,mesh/ordering=y varies,shader=interp,domain=0:3,domain y=0:3,samples=40, samples y=20] {-x*x+y};
addplot3[surf,mesh/ordering=y varies,shader=interp,domain=-3:0,domain y=0:-3,samples=40, samples y=20] {-x*x+y};
end{axis}
end{tikzpicture}
end{center}
end{document}

I cannot find a good view for display the function. I think I like the view from the x<0 and y<0 but it is the image and it is ugly. What do you recommend not using gnuplot?
Thanks!
EDIT. I also would like to graph 7 vectors with norm 1: 4 in the xy-plane, and 3 in the direction of x>0 and y>0. i.e.:

in 3D. If it is complicated to see, you can do it in 2D, like the image.
tikz-pgf
Probably we should do something with the graph atx>0andy>0(where the function is-x^2+y) because it is the ugliest part.
– manooooh
Oct 26 '18 at 23:28
1
I guess you could improve it somewhat by drawing the plots in a different order: first the plot on the right back, then left back, then right front and finally left front. But it is also a strange function that has jumps. You are sure you want this function?
– marmot
Oct 27 '18 at 0:58
@marmot I want this function. That's a bit better: imgur.com/a/YgRwgwY, anyway I would like to fill the "holes" (and draw the vectors with your help).
– manooooh
Oct 27 '18 at 1:01
Are these two separate graphs or do you want to add the arrows on the first graph? And what do you mean by "fill the holes"? Do you want to plot just one function?
– marmot
Oct 27 '18 at 1:14
@marmot if possible, I want to graph the7vectors with norm1in3D. That's probably bad (very bad), so the vectors in2D. This is a piecewise function, so all the four graphs are one function (in one graph). The "holes" are that spaces where the function is not plotted.
– manooooh
Oct 27 '18 at 1:19
add a comment |
I want to plot sqrt(-xy) if xy<=0, and -x^2+y if xy>0.
Please consider this MWE:
documentclass{article}
usepackage[utf8]{inputenc}
usepackage{pgfplots}
pgfplotsset{compat=1.8}
pgfplotsset{soldot/.style={color=black,only marks,mark=*}}
pgfplotsset{holdot/.style={color=red,fill=white,very thick,only marks,mark=*}}
begin{document}
begin{center}
begin{tikzpicture}[scale=2]
begin{axis}[
legend pos=outer north east,
axis lines = center,
view={-35}{15},
xticklabel style = {font=tiny},
yticklabel style = {font=tiny},
zticklabel style = {font=tiny},
xlabel = $x$,
ylabel = $y$,
zlabel = $z$,
legend style={cells={align=left}}
]
addplot3[surf,mesh/ordering=y varies,shader=interp,domain=-3:0,domain y=0:3,samples=40, samples y=20] {sqrt(-x*y)};
addplot3[surf,mesh/ordering=y varies,shader=interp,domain=0:3,domain y=0:-3,samples=40, samples y=20] {sqrt(-x*y)};
addplot3[surf,mesh/ordering=y varies,shader=interp,domain=0:3,domain y=0:3,samples=40, samples y=20] {-x*x+y};
addplot3[surf,mesh/ordering=y varies,shader=interp,domain=-3:0,domain y=0:-3,samples=40, samples y=20] {-x*x+y};
end{axis}
end{tikzpicture}
end{center}
end{document}

I cannot find a good view for display the function. I think I like the view from the x<0 and y<0 but it is the image and it is ugly. What do you recommend not using gnuplot?
Thanks!
EDIT. I also would like to graph 7 vectors with norm 1: 4 in the xy-plane, and 3 in the direction of x>0 and y>0. i.e.:

in 3D. If it is complicated to see, you can do it in 2D, like the image.
tikz-pgf
I want to plot sqrt(-xy) if xy<=0, and -x^2+y if xy>0.
Please consider this MWE:
documentclass{article}
usepackage[utf8]{inputenc}
usepackage{pgfplots}
pgfplotsset{compat=1.8}
pgfplotsset{soldot/.style={color=black,only marks,mark=*}}
pgfplotsset{holdot/.style={color=red,fill=white,very thick,only marks,mark=*}}
begin{document}
begin{center}
begin{tikzpicture}[scale=2]
begin{axis}[
legend pos=outer north east,
axis lines = center,
view={-35}{15},
xticklabel style = {font=tiny},
yticklabel style = {font=tiny},
zticklabel style = {font=tiny},
xlabel = $x$,
ylabel = $y$,
zlabel = $z$,
legend style={cells={align=left}}
]
addplot3[surf,mesh/ordering=y varies,shader=interp,domain=-3:0,domain y=0:3,samples=40, samples y=20] {sqrt(-x*y)};
addplot3[surf,mesh/ordering=y varies,shader=interp,domain=0:3,domain y=0:-3,samples=40, samples y=20] {sqrt(-x*y)};
addplot3[surf,mesh/ordering=y varies,shader=interp,domain=0:3,domain y=0:3,samples=40, samples y=20] {-x*x+y};
addplot3[surf,mesh/ordering=y varies,shader=interp,domain=-3:0,domain y=0:-3,samples=40, samples y=20] {-x*x+y};
end{axis}
end{tikzpicture}
end{center}
end{document}

I cannot find a good view for display the function. I think I like the view from the x<0 and y<0 but it is the image and it is ugly. What do you recommend not using gnuplot?
Thanks!
EDIT. I also would like to graph 7 vectors with norm 1: 4 in the xy-plane, and 3 in the direction of x>0 and y>0. i.e.:

in 3D. If it is complicated to see, you can do it in 2D, like the image.
tikz-pgf
tikz-pgf
edited 13 mins ago
Phelype Oleinik
23.6k54586
23.6k54586
asked Oct 26 '18 at 23:14
manoooohmanooooh
1,1291516
1,1291516
Probably we should do something with the graph atx>0andy>0(where the function is-x^2+y) because it is the ugliest part.
– manooooh
Oct 26 '18 at 23:28
1
I guess you could improve it somewhat by drawing the plots in a different order: first the plot on the right back, then left back, then right front and finally left front. But it is also a strange function that has jumps. You are sure you want this function?
– marmot
Oct 27 '18 at 0:58
@marmot I want this function. That's a bit better: imgur.com/a/YgRwgwY, anyway I would like to fill the "holes" (and draw the vectors with your help).
– manooooh
Oct 27 '18 at 1:01
Are these two separate graphs or do you want to add the arrows on the first graph? And what do you mean by "fill the holes"? Do you want to plot just one function?
– marmot
Oct 27 '18 at 1:14
@marmot if possible, I want to graph the7vectors with norm1in3D. That's probably bad (very bad), so the vectors in2D. This is a piecewise function, so all the four graphs are one function (in one graph). The "holes" are that spaces where the function is not plotted.
– manooooh
Oct 27 '18 at 1:19
add a comment |
Probably we should do something with the graph atx>0andy>0(where the function is-x^2+y) because it is the ugliest part.
– manooooh
Oct 26 '18 at 23:28
1
I guess you could improve it somewhat by drawing the plots in a different order: first the plot on the right back, then left back, then right front and finally left front. But it is also a strange function that has jumps. You are sure you want this function?
– marmot
Oct 27 '18 at 0:58
@marmot I want this function. That's a bit better: imgur.com/a/YgRwgwY, anyway I would like to fill the "holes" (and draw the vectors with your help).
– manooooh
Oct 27 '18 at 1:01
Are these two separate graphs or do you want to add the arrows on the first graph? And what do you mean by "fill the holes"? Do you want to plot just one function?
– marmot
Oct 27 '18 at 1:14
@marmot if possible, I want to graph the7vectors with norm1in3D. That's probably bad (very bad), so the vectors in2D. This is a piecewise function, so all the four graphs are one function (in one graph). The "holes" are that spaces where the function is not plotted.
– manooooh
Oct 27 '18 at 1:19
Probably we should do something with the graph at
x>0 and y>0 (where the function is -x^2+y) because it is the ugliest part.– manooooh
Oct 26 '18 at 23:28
Probably we should do something with the graph at
x>0 and y>0 (where the function is -x^2+y) because it is the ugliest part.– manooooh
Oct 26 '18 at 23:28
1
1
I guess you could improve it somewhat by drawing the plots in a different order: first the plot on the right back, then left back, then right front and finally left front. But it is also a strange function that has jumps. You are sure you want this function?
– marmot
Oct 27 '18 at 0:58
I guess you could improve it somewhat by drawing the plots in a different order: first the plot on the right back, then left back, then right front and finally left front. But it is also a strange function that has jumps. You are sure you want this function?
– marmot
Oct 27 '18 at 0:58
@marmot I want this function. That's a bit better: imgur.com/a/YgRwgwY, anyway I would like to fill the "holes" (and draw the vectors with your help).
– manooooh
Oct 27 '18 at 1:01
@marmot I want this function. That's a bit better: imgur.com/a/YgRwgwY, anyway I would like to fill the "holes" (and draw the vectors with your help).
– manooooh
Oct 27 '18 at 1:01
Are these two separate graphs or do you want to add the arrows on the first graph? And what do you mean by "fill the holes"? Do you want to plot just one function?
– marmot
Oct 27 '18 at 1:14
Are these two separate graphs or do you want to add the arrows on the first graph? And what do you mean by "fill the holes"? Do you want to plot just one function?
– marmot
Oct 27 '18 at 1:14
@marmot if possible, I want to graph the
7 vectors with norm 1 in 3D. That's probably bad (very bad), so the vectors in 2D. This is a piecewise function, so all the four graphs are one function (in one graph). The "holes" are that spaces where the function is not plotted.– manooooh
Oct 27 '18 at 1:19
@marmot if possible, I want to graph the
7 vectors with norm 1 in 3D. That's probably bad (very bad), so the vectors in 2D. This is a piecewise function, so all the four graphs are one function (in one graph). The "holes" are that spaces where the function is not plotted.– manooooh
Oct 27 '18 at 1:19
add a comment |
1 Answer
1
active
oldest
votes
Here's a proposal. Draw the axes by hand and hide what you have to hide.
documentclass[tikz,border=3.14mm]{standalone}
usepackage{pgfplots}
pgfplotsset{compat=1.16}
begin{document}
begin{tikzpicture}[scale=2,
declare function={f(x,y)=ifthenelse(x*y<0,sqrt(-x*y),-x*x+y);}]
begin{axis}[hide axis,
legend pos=outer north east,
view={75}{45},clip=false
]
draw[thick,-stealth] (0,0,0) -- (0,4,0) node[right]{$y$};
addplot3[opacity=0.8,surf,mesh/ordering=y varies,shader=interp,domain=-3:3,domain
y=-3:3,samples=61, samples y=61,on layer=axis background] {f(x,y)};
addlegendentry{$f(x,y)$}
draw[thick,-stealth] (0,0,0) -- (0,0,4) node[right]{$z$};
draw[thick,-stealth] (0,0,0) -- (4,0,0) node[right]{$x$};
end{axis}
end{tikzpicture}
end{document}

Any attempt to draw these unit vectors in the positive x-y plane does IMHO not look good. How about drawing them in the negative x-y plane?
documentclass[tikz,border=3.14mm]{standalone}
usepackage{pgfplots}
pgfplotsset{compat=1.16}
begin{document}
begin{tikzpicture}[scale=2,
declare function={f(x,y)=ifthenelse(x*y<0,sqrt(-x*y),-x*x+y);}]
begin{axis}[hide axis,
legend pos=outer north east,
view={-145}{45},clip=false
]
addplot3[opacity=0.8,surf,mesh/ordering=y varies,shader=interp,domain=-3:3,domain
y=-3:3,samples=61, samples y=61,on layer=axis background] {f(x,y)};
addlegendentry{$f(x,y)$}
draw[thick,-stealth] (0,0,0) -- (0,4,0) node[below]{$y$};
draw[thick,-stealth] (0,0,0) -- (0,0,4) node[right]{$z$};
draw[thick,-stealth] (0,0,0) -- (4,0,0) node[above]{$x$};
pgfplotsinvokeforeach{0,22.5,...,90}{%
draw[thick,-stealth] (0,0,0) -- ({-cos(#1)},{-sin(#1)},0);}
end{axis}
end{tikzpicture}
end{document}

Here's a third version with ticks.
documentclass[tikz,border=3.14mm]{standalone}
usepackage{pgfplots}
pgfplotsset{compat=1.16}
begin{document}
begin{tikzpicture}[scale=2,
declare function={f(x,y)=ifthenelse(x*y<0,sqrt(-x*y),-x*x+y);}]
begin{axis}[axis on top,xlabel={$x$},ylabel={$y$},
axis lines=middle,xtick={-1,0,1},ytick={-1,0,1},
legend pos=outer north east,
z axis line style={opacity=0},
view={-145}{45},clip=false
]
addplot3[opacity=0.8,surf,mesh/ordering=y varies,shader=interp,domain=-3:3,domain
y=-3:3,samples=61, samples y=61,on layer=axis background] {f(x,y)};
addlegendentry{$f(x,y)$}
draw[-stealth] (0,0,0) -- (0,0,4) node[right]{$z$};
pgfplotsinvokeforeach{0,22.5,...,90}{%
draw[-stealth] (0,0,0) -- ({-cos(#1)},{-sin(#1)},0);}
end{axis}
end{tikzpicture}
end{document}

Great! If the graph + vectors is ugly thenf(x,y)in one graph (like your MWE), and vectors in another one (probablyview={0}{90}). If you find an excellent view where the graph + vectors looks nice, then one graph.:)
– manooooh
Oct 27 '18 at 1:26
The second part of your question I still don't understand. Do you want to draw these vectors in this plot or in a separate plot? hmmm... now your plot is much better, but I think that the only vector which we could not see will bev=(0,-1). Can you find a better view where we could see the 7 vectors with norm1? If "no" then plots it in a new graph withview={0}{90}(if you want).
– manooooh
Oct 27 '18 at 7:17
1
@manooooh Thanks for your edit here. I have a new proposal. What do you think? (I will go cycling now but will be back in a few hours.)
– marmot
Oct 27 '18 at 19:14
You're welcome and awesome!! I only did a few changes:view={-145}{45}->view={145}{45}; added the vectors(-1,0)and(0,-1)(and changed the direction fromdraw[thick,-stealth] (0,0,0) -- ({-cos(#1)},{-sin(#1)},0);todraw[blue,thick,-stealth] (0,0,0) -- ({cos(#1)},{sin(#1)},0);); and deleteopacity=0.8. Very easy code, thanks!!
– manooooh
Oct 27 '18 at 20:18
1
@manooooh If you hide only the z axis and draw it by hand, you can add ticks.
– marmot
Oct 27 '18 at 22:51
|
show 2 more comments
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
});
}
});
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%2f456987%2ffind-a-good-view-for-a-function-by-parts-using-tikzpicture-environment%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
Here's a proposal. Draw the axes by hand and hide what you have to hide.
documentclass[tikz,border=3.14mm]{standalone}
usepackage{pgfplots}
pgfplotsset{compat=1.16}
begin{document}
begin{tikzpicture}[scale=2,
declare function={f(x,y)=ifthenelse(x*y<0,sqrt(-x*y),-x*x+y);}]
begin{axis}[hide axis,
legend pos=outer north east,
view={75}{45},clip=false
]
draw[thick,-stealth] (0,0,0) -- (0,4,0) node[right]{$y$};
addplot3[opacity=0.8,surf,mesh/ordering=y varies,shader=interp,domain=-3:3,domain
y=-3:3,samples=61, samples y=61,on layer=axis background] {f(x,y)};
addlegendentry{$f(x,y)$}
draw[thick,-stealth] (0,0,0) -- (0,0,4) node[right]{$z$};
draw[thick,-stealth] (0,0,0) -- (4,0,0) node[right]{$x$};
end{axis}
end{tikzpicture}
end{document}

Any attempt to draw these unit vectors in the positive x-y plane does IMHO not look good. How about drawing them in the negative x-y plane?
documentclass[tikz,border=3.14mm]{standalone}
usepackage{pgfplots}
pgfplotsset{compat=1.16}
begin{document}
begin{tikzpicture}[scale=2,
declare function={f(x,y)=ifthenelse(x*y<0,sqrt(-x*y),-x*x+y);}]
begin{axis}[hide axis,
legend pos=outer north east,
view={-145}{45},clip=false
]
addplot3[opacity=0.8,surf,mesh/ordering=y varies,shader=interp,domain=-3:3,domain
y=-3:3,samples=61, samples y=61,on layer=axis background] {f(x,y)};
addlegendentry{$f(x,y)$}
draw[thick,-stealth] (0,0,0) -- (0,4,0) node[below]{$y$};
draw[thick,-stealth] (0,0,0) -- (0,0,4) node[right]{$z$};
draw[thick,-stealth] (0,0,0) -- (4,0,0) node[above]{$x$};
pgfplotsinvokeforeach{0,22.5,...,90}{%
draw[thick,-stealth] (0,0,0) -- ({-cos(#1)},{-sin(#1)},0);}
end{axis}
end{tikzpicture}
end{document}

Here's a third version with ticks.
documentclass[tikz,border=3.14mm]{standalone}
usepackage{pgfplots}
pgfplotsset{compat=1.16}
begin{document}
begin{tikzpicture}[scale=2,
declare function={f(x,y)=ifthenelse(x*y<0,sqrt(-x*y),-x*x+y);}]
begin{axis}[axis on top,xlabel={$x$},ylabel={$y$},
axis lines=middle,xtick={-1,0,1},ytick={-1,0,1},
legend pos=outer north east,
z axis line style={opacity=0},
view={-145}{45},clip=false
]
addplot3[opacity=0.8,surf,mesh/ordering=y varies,shader=interp,domain=-3:3,domain
y=-3:3,samples=61, samples y=61,on layer=axis background] {f(x,y)};
addlegendentry{$f(x,y)$}
draw[-stealth] (0,0,0) -- (0,0,4) node[right]{$z$};
pgfplotsinvokeforeach{0,22.5,...,90}{%
draw[-stealth] (0,0,0) -- ({-cos(#1)},{-sin(#1)},0);}
end{axis}
end{tikzpicture}
end{document}

Great! If the graph + vectors is ugly thenf(x,y)in one graph (like your MWE), and vectors in another one (probablyview={0}{90}). If you find an excellent view where the graph + vectors looks nice, then one graph.:)
– manooooh
Oct 27 '18 at 1:26
The second part of your question I still don't understand. Do you want to draw these vectors in this plot or in a separate plot? hmmm... now your plot is much better, but I think that the only vector which we could not see will bev=(0,-1). Can you find a better view where we could see the 7 vectors with norm1? If "no" then plots it in a new graph withview={0}{90}(if you want).
– manooooh
Oct 27 '18 at 7:17
1
@manooooh Thanks for your edit here. I have a new proposal. What do you think? (I will go cycling now but will be back in a few hours.)
– marmot
Oct 27 '18 at 19:14
You're welcome and awesome!! I only did a few changes:view={-145}{45}->view={145}{45}; added the vectors(-1,0)and(0,-1)(and changed the direction fromdraw[thick,-stealth] (0,0,0) -- ({-cos(#1)},{-sin(#1)},0);todraw[blue,thick,-stealth] (0,0,0) -- ({cos(#1)},{sin(#1)},0);); and deleteopacity=0.8. Very easy code, thanks!!
– manooooh
Oct 27 '18 at 20:18
1
@manooooh If you hide only the z axis and draw it by hand, you can add ticks.
– marmot
Oct 27 '18 at 22:51
|
show 2 more comments
Here's a proposal. Draw the axes by hand and hide what you have to hide.
documentclass[tikz,border=3.14mm]{standalone}
usepackage{pgfplots}
pgfplotsset{compat=1.16}
begin{document}
begin{tikzpicture}[scale=2,
declare function={f(x,y)=ifthenelse(x*y<0,sqrt(-x*y),-x*x+y);}]
begin{axis}[hide axis,
legend pos=outer north east,
view={75}{45},clip=false
]
draw[thick,-stealth] (0,0,0) -- (0,4,0) node[right]{$y$};
addplot3[opacity=0.8,surf,mesh/ordering=y varies,shader=interp,domain=-3:3,domain
y=-3:3,samples=61, samples y=61,on layer=axis background] {f(x,y)};
addlegendentry{$f(x,y)$}
draw[thick,-stealth] (0,0,0) -- (0,0,4) node[right]{$z$};
draw[thick,-stealth] (0,0,0) -- (4,0,0) node[right]{$x$};
end{axis}
end{tikzpicture}
end{document}

Any attempt to draw these unit vectors in the positive x-y plane does IMHO not look good. How about drawing them in the negative x-y plane?
documentclass[tikz,border=3.14mm]{standalone}
usepackage{pgfplots}
pgfplotsset{compat=1.16}
begin{document}
begin{tikzpicture}[scale=2,
declare function={f(x,y)=ifthenelse(x*y<0,sqrt(-x*y),-x*x+y);}]
begin{axis}[hide axis,
legend pos=outer north east,
view={-145}{45},clip=false
]
addplot3[opacity=0.8,surf,mesh/ordering=y varies,shader=interp,domain=-3:3,domain
y=-3:3,samples=61, samples y=61,on layer=axis background] {f(x,y)};
addlegendentry{$f(x,y)$}
draw[thick,-stealth] (0,0,0) -- (0,4,0) node[below]{$y$};
draw[thick,-stealth] (0,0,0) -- (0,0,4) node[right]{$z$};
draw[thick,-stealth] (0,0,0) -- (4,0,0) node[above]{$x$};
pgfplotsinvokeforeach{0,22.5,...,90}{%
draw[thick,-stealth] (0,0,0) -- ({-cos(#1)},{-sin(#1)},0);}
end{axis}
end{tikzpicture}
end{document}

Here's a third version with ticks.
documentclass[tikz,border=3.14mm]{standalone}
usepackage{pgfplots}
pgfplotsset{compat=1.16}
begin{document}
begin{tikzpicture}[scale=2,
declare function={f(x,y)=ifthenelse(x*y<0,sqrt(-x*y),-x*x+y);}]
begin{axis}[axis on top,xlabel={$x$},ylabel={$y$},
axis lines=middle,xtick={-1,0,1},ytick={-1,0,1},
legend pos=outer north east,
z axis line style={opacity=0},
view={-145}{45},clip=false
]
addplot3[opacity=0.8,surf,mesh/ordering=y varies,shader=interp,domain=-3:3,domain
y=-3:3,samples=61, samples y=61,on layer=axis background] {f(x,y)};
addlegendentry{$f(x,y)$}
draw[-stealth] (0,0,0) -- (0,0,4) node[right]{$z$};
pgfplotsinvokeforeach{0,22.5,...,90}{%
draw[-stealth] (0,0,0) -- ({-cos(#1)},{-sin(#1)},0);}
end{axis}
end{tikzpicture}
end{document}

Great! If the graph + vectors is ugly thenf(x,y)in one graph (like your MWE), and vectors in another one (probablyview={0}{90}). If you find an excellent view where the graph + vectors looks nice, then one graph.:)
– manooooh
Oct 27 '18 at 1:26
The second part of your question I still don't understand. Do you want to draw these vectors in this plot or in a separate plot? hmmm... now your plot is much better, but I think that the only vector which we could not see will bev=(0,-1). Can you find a better view where we could see the 7 vectors with norm1? If "no" then plots it in a new graph withview={0}{90}(if you want).
– manooooh
Oct 27 '18 at 7:17
1
@manooooh Thanks for your edit here. I have a new proposal. What do you think? (I will go cycling now but will be back in a few hours.)
– marmot
Oct 27 '18 at 19:14
You're welcome and awesome!! I only did a few changes:view={-145}{45}->view={145}{45}; added the vectors(-1,0)and(0,-1)(and changed the direction fromdraw[thick,-stealth] (0,0,0) -- ({-cos(#1)},{-sin(#1)},0);todraw[blue,thick,-stealth] (0,0,0) -- ({cos(#1)},{sin(#1)},0);); and deleteopacity=0.8. Very easy code, thanks!!
– manooooh
Oct 27 '18 at 20:18
1
@manooooh If you hide only the z axis and draw it by hand, you can add ticks.
– marmot
Oct 27 '18 at 22:51
|
show 2 more comments
Here's a proposal. Draw the axes by hand and hide what you have to hide.
documentclass[tikz,border=3.14mm]{standalone}
usepackage{pgfplots}
pgfplotsset{compat=1.16}
begin{document}
begin{tikzpicture}[scale=2,
declare function={f(x,y)=ifthenelse(x*y<0,sqrt(-x*y),-x*x+y);}]
begin{axis}[hide axis,
legend pos=outer north east,
view={75}{45},clip=false
]
draw[thick,-stealth] (0,0,0) -- (0,4,0) node[right]{$y$};
addplot3[opacity=0.8,surf,mesh/ordering=y varies,shader=interp,domain=-3:3,domain
y=-3:3,samples=61, samples y=61,on layer=axis background] {f(x,y)};
addlegendentry{$f(x,y)$}
draw[thick,-stealth] (0,0,0) -- (0,0,4) node[right]{$z$};
draw[thick,-stealth] (0,0,0) -- (4,0,0) node[right]{$x$};
end{axis}
end{tikzpicture}
end{document}

Any attempt to draw these unit vectors in the positive x-y plane does IMHO not look good. How about drawing them in the negative x-y plane?
documentclass[tikz,border=3.14mm]{standalone}
usepackage{pgfplots}
pgfplotsset{compat=1.16}
begin{document}
begin{tikzpicture}[scale=2,
declare function={f(x,y)=ifthenelse(x*y<0,sqrt(-x*y),-x*x+y);}]
begin{axis}[hide axis,
legend pos=outer north east,
view={-145}{45},clip=false
]
addplot3[opacity=0.8,surf,mesh/ordering=y varies,shader=interp,domain=-3:3,domain
y=-3:3,samples=61, samples y=61,on layer=axis background] {f(x,y)};
addlegendentry{$f(x,y)$}
draw[thick,-stealth] (0,0,0) -- (0,4,0) node[below]{$y$};
draw[thick,-stealth] (0,0,0) -- (0,0,4) node[right]{$z$};
draw[thick,-stealth] (0,0,0) -- (4,0,0) node[above]{$x$};
pgfplotsinvokeforeach{0,22.5,...,90}{%
draw[thick,-stealth] (0,0,0) -- ({-cos(#1)},{-sin(#1)},0);}
end{axis}
end{tikzpicture}
end{document}

Here's a third version with ticks.
documentclass[tikz,border=3.14mm]{standalone}
usepackage{pgfplots}
pgfplotsset{compat=1.16}
begin{document}
begin{tikzpicture}[scale=2,
declare function={f(x,y)=ifthenelse(x*y<0,sqrt(-x*y),-x*x+y);}]
begin{axis}[axis on top,xlabel={$x$},ylabel={$y$},
axis lines=middle,xtick={-1,0,1},ytick={-1,0,1},
legend pos=outer north east,
z axis line style={opacity=0},
view={-145}{45},clip=false
]
addplot3[opacity=0.8,surf,mesh/ordering=y varies,shader=interp,domain=-3:3,domain
y=-3:3,samples=61, samples y=61,on layer=axis background] {f(x,y)};
addlegendentry{$f(x,y)$}
draw[-stealth] (0,0,0) -- (0,0,4) node[right]{$z$};
pgfplotsinvokeforeach{0,22.5,...,90}{%
draw[-stealth] (0,0,0) -- ({-cos(#1)},{-sin(#1)},0);}
end{axis}
end{tikzpicture}
end{document}

Here's a proposal. Draw the axes by hand and hide what you have to hide.
documentclass[tikz,border=3.14mm]{standalone}
usepackage{pgfplots}
pgfplotsset{compat=1.16}
begin{document}
begin{tikzpicture}[scale=2,
declare function={f(x,y)=ifthenelse(x*y<0,sqrt(-x*y),-x*x+y);}]
begin{axis}[hide axis,
legend pos=outer north east,
view={75}{45},clip=false
]
draw[thick,-stealth] (0,0,0) -- (0,4,0) node[right]{$y$};
addplot3[opacity=0.8,surf,mesh/ordering=y varies,shader=interp,domain=-3:3,domain
y=-3:3,samples=61, samples y=61,on layer=axis background] {f(x,y)};
addlegendentry{$f(x,y)$}
draw[thick,-stealth] (0,0,0) -- (0,0,4) node[right]{$z$};
draw[thick,-stealth] (0,0,0) -- (4,0,0) node[right]{$x$};
end{axis}
end{tikzpicture}
end{document}

Any attempt to draw these unit vectors in the positive x-y plane does IMHO not look good. How about drawing them in the negative x-y plane?
documentclass[tikz,border=3.14mm]{standalone}
usepackage{pgfplots}
pgfplotsset{compat=1.16}
begin{document}
begin{tikzpicture}[scale=2,
declare function={f(x,y)=ifthenelse(x*y<0,sqrt(-x*y),-x*x+y);}]
begin{axis}[hide axis,
legend pos=outer north east,
view={-145}{45},clip=false
]
addplot3[opacity=0.8,surf,mesh/ordering=y varies,shader=interp,domain=-3:3,domain
y=-3:3,samples=61, samples y=61,on layer=axis background] {f(x,y)};
addlegendentry{$f(x,y)$}
draw[thick,-stealth] (0,0,0) -- (0,4,0) node[below]{$y$};
draw[thick,-stealth] (0,0,0) -- (0,0,4) node[right]{$z$};
draw[thick,-stealth] (0,0,0) -- (4,0,0) node[above]{$x$};
pgfplotsinvokeforeach{0,22.5,...,90}{%
draw[thick,-stealth] (0,0,0) -- ({-cos(#1)},{-sin(#1)},0);}
end{axis}
end{tikzpicture}
end{document}

Here's a third version with ticks.
documentclass[tikz,border=3.14mm]{standalone}
usepackage{pgfplots}
pgfplotsset{compat=1.16}
begin{document}
begin{tikzpicture}[scale=2,
declare function={f(x,y)=ifthenelse(x*y<0,sqrt(-x*y),-x*x+y);}]
begin{axis}[axis on top,xlabel={$x$},ylabel={$y$},
axis lines=middle,xtick={-1,0,1},ytick={-1,0,1},
legend pos=outer north east,
z axis line style={opacity=0},
view={-145}{45},clip=false
]
addplot3[opacity=0.8,surf,mesh/ordering=y varies,shader=interp,domain=-3:3,domain
y=-3:3,samples=61, samples y=61,on layer=axis background] {f(x,y)};
addlegendentry{$f(x,y)$}
draw[-stealth] (0,0,0) -- (0,0,4) node[right]{$z$};
pgfplotsinvokeforeach{0,22.5,...,90}{%
draw[-stealth] (0,0,0) -- ({-cos(#1)},{-sin(#1)},0);}
end{axis}
end{tikzpicture}
end{document}

edited Oct 27 '18 at 22:50
answered Oct 27 '18 at 1:23
marmotmarmot
104k4123234
104k4123234
Great! If the graph + vectors is ugly thenf(x,y)in one graph (like your MWE), and vectors in another one (probablyview={0}{90}). If you find an excellent view where the graph + vectors looks nice, then one graph.:)
– manooooh
Oct 27 '18 at 1:26
The second part of your question I still don't understand. Do you want to draw these vectors in this plot or in a separate plot? hmmm... now your plot is much better, but I think that the only vector which we could not see will bev=(0,-1). Can you find a better view where we could see the 7 vectors with norm1? If "no" then plots it in a new graph withview={0}{90}(if you want).
– manooooh
Oct 27 '18 at 7:17
1
@manooooh Thanks for your edit here. I have a new proposal. What do you think? (I will go cycling now but will be back in a few hours.)
– marmot
Oct 27 '18 at 19:14
You're welcome and awesome!! I only did a few changes:view={-145}{45}->view={145}{45}; added the vectors(-1,0)and(0,-1)(and changed the direction fromdraw[thick,-stealth] (0,0,0) -- ({-cos(#1)},{-sin(#1)},0);todraw[blue,thick,-stealth] (0,0,0) -- ({cos(#1)},{sin(#1)},0);); and deleteopacity=0.8. Very easy code, thanks!!
– manooooh
Oct 27 '18 at 20:18
1
@manooooh If you hide only the z axis and draw it by hand, you can add ticks.
– marmot
Oct 27 '18 at 22:51
|
show 2 more comments
Great! If the graph + vectors is ugly thenf(x,y)in one graph (like your MWE), and vectors in another one (probablyview={0}{90}). If you find an excellent view where the graph + vectors looks nice, then one graph.:)
– manooooh
Oct 27 '18 at 1:26
The second part of your question I still don't understand. Do you want to draw these vectors in this plot or in a separate plot? hmmm... now your plot is much better, but I think that the only vector which we could not see will bev=(0,-1). Can you find a better view where we could see the 7 vectors with norm1? If "no" then plots it in a new graph withview={0}{90}(if you want).
– manooooh
Oct 27 '18 at 7:17
1
@manooooh Thanks for your edit here. I have a new proposal. What do you think? (I will go cycling now but will be back in a few hours.)
– marmot
Oct 27 '18 at 19:14
You're welcome and awesome!! I only did a few changes:view={-145}{45}->view={145}{45}; added the vectors(-1,0)and(0,-1)(and changed the direction fromdraw[thick,-stealth] (0,0,0) -- ({-cos(#1)},{-sin(#1)},0);todraw[blue,thick,-stealth] (0,0,0) -- ({cos(#1)},{sin(#1)},0);); and deleteopacity=0.8. Very easy code, thanks!!
– manooooh
Oct 27 '18 at 20:18
1
@manooooh If you hide only the z axis and draw it by hand, you can add ticks.
– marmot
Oct 27 '18 at 22:51
Great! If the graph + vectors is ugly then
f(x,y) in one graph (like your MWE), and vectors in another one (probably view={0}{90}). If you find an excellent view where the graph + vectors looks nice, then one graph. :)– manooooh
Oct 27 '18 at 1:26
Great! If the graph + vectors is ugly then
f(x,y) in one graph (like your MWE), and vectors in another one (probably view={0}{90}). If you find an excellent view where the graph + vectors looks nice, then one graph. :)– manooooh
Oct 27 '18 at 1:26
The second part of your question I still don't understand. Do you want to draw these vectors in this plot or in a separate plot? hmmm... now your plot is much better, but I think that the only vector which we could not see will be
v=(0,-1). Can you find a better view where we could see the 7 vectors with norm 1? If "no" then plots it in a new graph with view={0}{90} (if you want).– manooooh
Oct 27 '18 at 7:17
The second part of your question I still don't understand. Do you want to draw these vectors in this plot or in a separate plot? hmmm... now your plot is much better, but I think that the only vector which we could not see will be
v=(0,-1). Can you find a better view where we could see the 7 vectors with norm 1? If "no" then plots it in a new graph with view={0}{90} (if you want).– manooooh
Oct 27 '18 at 7:17
1
1
@manooooh Thanks for your edit here. I have a new proposal. What do you think? (I will go cycling now but will be back in a few hours.)
– marmot
Oct 27 '18 at 19:14
@manooooh Thanks for your edit here. I have a new proposal. What do you think? (I will go cycling now but will be back in a few hours.)
– marmot
Oct 27 '18 at 19:14
You're welcome and awesome!! I only did a few changes:
view={-145}{45} -> view={145}{45}; added the vectors (-1,0) and (0,-1) (and changed the direction from draw[thick,-stealth] (0,0,0) -- ({-cos(#1)},{-sin(#1)},0); to draw[blue,thick,-stealth] (0,0,0) -- ({cos(#1)},{sin(#1)},0);); and delete opacity=0.8. Very easy code, thanks!!– manooooh
Oct 27 '18 at 20:18
You're welcome and awesome!! I only did a few changes:
view={-145}{45} -> view={145}{45}; added the vectors (-1,0) and (0,-1) (and changed the direction from draw[thick,-stealth] (0,0,0) -- ({-cos(#1)},{-sin(#1)},0); to draw[blue,thick,-stealth] (0,0,0) -- ({cos(#1)},{sin(#1)},0);); and delete opacity=0.8. Very easy code, thanks!!– manooooh
Oct 27 '18 at 20:18
1
1
@manooooh If you hide only the z axis and draw it by hand, you can add ticks.
– marmot
Oct 27 '18 at 22:51
@manooooh If you hide only the z axis and draw it by hand, you can add ticks.
– marmot
Oct 27 '18 at 22:51
|
show 2 more comments
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%2f456987%2ffind-a-good-view-for-a-function-by-parts-using-tikzpicture-environment%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
Probably we should do something with the graph at
x>0andy>0(where the function is-x^2+y) because it is the ugliest part.– manooooh
Oct 26 '18 at 23:28
1
I guess you could improve it somewhat by drawing the plots in a different order: first the plot on the right back, then left back, then right front and finally left front. But it is also a strange function that has jumps. You are sure you want this function?
– marmot
Oct 27 '18 at 0:58
@marmot I want this function. That's a bit better: imgur.com/a/YgRwgwY, anyway I would like to fill the "holes" (and draw the vectors with your help).
– manooooh
Oct 27 '18 at 1:01
Are these two separate graphs or do you want to add the arrows on the first graph? And what do you mean by "fill the holes"? Do you want to plot just one function?
– marmot
Oct 27 '18 at 1:14
@marmot if possible, I want to graph the
7vectors with norm1in3D. That's probably bad (very bad), so the vectors in2D. This is a piecewise function, so all the four graphs are one function (in one graph). The "holes" are that spaces where the function is not plotted.– manooooh
Oct 27 '18 at 1:19