Arbitrary Curve in Tikz











up vote
6
down vote

favorite
3












How can I improve this curve? Why do the arrows ruin the left side but keep the right side smooth? All suggestions welcome.



documentclass{article}
usepackage{tikz}
begin{document}
begin{tikzpicture}[scale=.6,cap=round]
tikzset{axes/.style={}}
% The graphic
begin{scope}[style=axes]
draw[->] (-5,0) -- (5,0) node[below] {$x$};
draw[->] (0,-3)-- (0,5) node[left] {$y$};
%draw [gray!50] (-5,3) -- (-2.5,1) -- (2.5,4) -- (5,-1);
draw [red,thick,<->] plot [smooth,samples=200, tension=1] coordinates {
(-5,4) (-2.5,1) (2.5,4) (5,-1)};
end{scope}
end{tikzpicture}
end{document}


enter image description here










share|improve this question






















  • @Marmot yes I saw that but forgot to delete. If you remove <-> from the draw command there is a less "kink" in the output on the left. I was not sure why? Your hobby library allows the end arrows, so I will mark answered now
    – MathScholar
    Nov 15 at 12:13












  • I see. I expanded my answer by adding a explanation why that happens, hand how it can be prevented.
    – marmot
    Nov 15 at 14:55










  • @Marmot, thank you for getting back to me on this. I will start using the second answer but look into the hobby package later. Again Thanks Marmot!
    – MathScholar
    Nov 16 at 0:39















up vote
6
down vote

favorite
3












How can I improve this curve? Why do the arrows ruin the left side but keep the right side smooth? All suggestions welcome.



documentclass{article}
usepackage{tikz}
begin{document}
begin{tikzpicture}[scale=.6,cap=round]
tikzset{axes/.style={}}
% The graphic
begin{scope}[style=axes]
draw[->] (-5,0) -- (5,0) node[below] {$x$};
draw[->] (0,-3)-- (0,5) node[left] {$y$};
%draw [gray!50] (-5,3) -- (-2.5,1) -- (2.5,4) -- (5,-1);
draw [red,thick,<->] plot [smooth,samples=200, tension=1] coordinates {
(-5,4) (-2.5,1) (2.5,4) (5,-1)};
end{scope}
end{tikzpicture}
end{document}


enter image description here










share|improve this question






















  • @Marmot yes I saw that but forgot to delete. If you remove <-> from the draw command there is a less "kink" in the output on the left. I was not sure why? Your hobby library allows the end arrows, so I will mark answered now
    – MathScholar
    Nov 15 at 12:13












  • I see. I expanded my answer by adding a explanation why that happens, hand how it can be prevented.
    – marmot
    Nov 15 at 14:55










  • @Marmot, thank you for getting back to me on this. I will start using the second answer but look into the hobby package later. Again Thanks Marmot!
    – MathScholar
    Nov 16 at 0:39













up vote
6
down vote

favorite
3









up vote
6
down vote

favorite
3






3





How can I improve this curve? Why do the arrows ruin the left side but keep the right side smooth? All suggestions welcome.



documentclass{article}
usepackage{tikz}
begin{document}
begin{tikzpicture}[scale=.6,cap=round]
tikzset{axes/.style={}}
% The graphic
begin{scope}[style=axes]
draw[->] (-5,0) -- (5,0) node[below] {$x$};
draw[->] (0,-3)-- (0,5) node[left] {$y$};
%draw [gray!50] (-5,3) -- (-2.5,1) -- (2.5,4) -- (5,-1);
draw [red,thick,<->] plot [smooth,samples=200, tension=1] coordinates {
(-5,4) (-2.5,1) (2.5,4) (5,-1)};
end{scope}
end{tikzpicture}
end{document}


enter image description here










share|improve this question













How can I improve this curve? Why do the arrows ruin the left side but keep the right side smooth? All suggestions welcome.



documentclass{article}
usepackage{tikz}
begin{document}
begin{tikzpicture}[scale=.6,cap=round]
tikzset{axes/.style={}}
% The graphic
begin{scope}[style=axes]
draw[->] (-5,0) -- (5,0) node[below] {$x$};
draw[->] (0,-3)-- (0,5) node[left] {$y$};
%draw [gray!50] (-5,3) -- (-2.5,1) -- (2.5,4) -- (5,-1);
draw [red,thick,<->] plot [smooth,samples=200, tension=1] coordinates {
(-5,4) (-2.5,1) (2.5,4) (5,-1)};
end{scope}
end{tikzpicture}
end{document}


enter image description here







tikz-pgf






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 15 at 4:18









MathScholar

4238




4238












  • @Marmot yes I saw that but forgot to delete. If you remove <-> from the draw command there is a less "kink" in the output on the left. I was not sure why? Your hobby library allows the end arrows, so I will mark answered now
    – MathScholar
    Nov 15 at 12:13












  • I see. I expanded my answer by adding a explanation why that happens, hand how it can be prevented.
    – marmot
    Nov 15 at 14:55










  • @Marmot, thank you for getting back to me on this. I will start using the second answer but look into the hobby package later. Again Thanks Marmot!
    – MathScholar
    Nov 16 at 0:39


















  • @Marmot yes I saw that but forgot to delete. If you remove <-> from the draw command there is a less "kink" in the output on the left. I was not sure why? Your hobby library allows the end arrows, so I will mark answered now
    – MathScholar
    Nov 15 at 12:13












  • I see. I expanded my answer by adding a explanation why that happens, hand how it can be prevented.
    – marmot
    Nov 15 at 14:55










  • @Marmot, thank you for getting back to me on this. I will start using the second answer but look into the hobby package later. Again Thanks Marmot!
    – MathScholar
    Nov 16 at 0:39
















@Marmot yes I saw that but forgot to delete. If you remove <-> from the draw command there is a less "kink" in the output on the left. I was not sure why? Your hobby library allows the end arrows, so I will mark answered now
– MathScholar
Nov 15 at 12:13






@Marmot yes I saw that but forgot to delete. If you remove <-> from the draw command there is a less "kink" in the output on the left. I was not sure why? Your hobby library allows the end arrows, so I will mark answered now
– MathScholar
Nov 15 at 12:13














I see. I expanded my answer by adding a explanation why that happens, hand how it can be prevented.
– marmot
Nov 15 at 14:55




I see. I expanded my answer by adding a explanation why that happens, hand how it can be prevented.
– marmot
Nov 15 at 14:55












@Marmot, thank you for getting back to me on this. I will start using the second answer but look into the hobby package later. Again Thanks Marmot!
– MathScholar
Nov 16 at 0:39




@Marmot, thank you for getting back to me on this. I will start using the second answer but look into the hobby package later. Again Thanks Marmot!
– MathScholar
Nov 16 at 0:39










1 Answer
1






active

oldest

votes

















up vote
5
down vote



accepted










I do not precisely understand what you mean by "Why do the arrows ruin the left side but keep the right side smooth? ". However, this is just to say that there are many possible ways to draw smooth curves with TikZ. A rather powerful way is to employ the hobby library.



documentclass{article}
usepackage{tikz}
usetikzlibrary{hobby}
begin{document}
begin{tikzpicture}[scale=.6,cap=round,
tangent/.style={%
in angle={(180+#1)} ,
Hobby finish ,
designated Hobby path=next , out angle=#1,
}]
tikzset{axes/.style={}}
% The graphic
begin{scope}[style=axes]
draw[->] (-5,0) -- (5,0) node[below] {$x$};
draw[->] (0,-3)-- (0,5) node[left] {$y$};
%draw [gray!50] (-5,3) -- (-2.5,1) -- (2.5,4) -- (5,-1);
draw [red,thick,<->,use Hobby shortcut]
([tangent=-80]-5,4) .. (-2.5,1) .. (2.5,4) .. ([tangent=-80]5,-1);
end{scope}
end{tikzpicture}
end{document}


enter image description here



Does this come closer to what you want to achieve?



ADDENDUM: You are asking about the distortion you get when you add or remove an arrow. The effect you are referring to is clearly visible as the difference between the red and blue curves in



documentclass{article}
usepackage{tikz}
%usetikzlibrary{bending}
begin{document}
begin{tikzpicture}[scale=.6,cap=round]
tikzset{axes/.style={}}
% The graphic
begin{scope}[style=axes]
draw[->] (-5,0) -- (5,0) node[below] {$x$};
draw[->] (0,-3)-- (0,5) node[left] {$y$};
%draw [gray!50] (-5,3) -- (-2.5,1) -- (2.5,4) -- (5,-1);
draw [red,thick,<->] plot [smooth,tension=1] coordinates {
(-5,4) (-2.5,1) (2.5,4) (5,-1)};
draw [blue,thick,-] plot [smooth,tension=1] coordinates {
(-5,4) (-2.5,1) (2.5,4) (5,-1)};
end{scope}
end{tikzpicture}
end{document}


enter image description here



This effect is due to the fact that a (standard) arrow inserts a stretch of straight (as opposed to curved) path. You can simply get rid of it by activating usetikzlibrary{bending}, i.e. by removing the % in front of it.



enter image description here



Of course, if you have longer arrows, you want to make sure that you load arrows.meta as well and pass bend to the options of the arrow, e.g. `



 draw [red,thick,{Latex[bend,length=5pt]}-{Latex[bend,length=5pt]}] plot [smooth,tension=1] coordinates { 
(-5,4) (-2.5,1) (2.5,4) (5,-1)};





share|improve this answer























  • Thanks Marmot, this output is what I need. Again the program I posted works without end arrows, but this Hobby library is new to me as well!
    – MathScholar
    Nov 15 at 12:23













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


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f460058%2farbitrary-curve-in-tikz%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
5
down vote



accepted










I do not precisely understand what you mean by "Why do the arrows ruin the left side but keep the right side smooth? ". However, this is just to say that there are many possible ways to draw smooth curves with TikZ. A rather powerful way is to employ the hobby library.



documentclass{article}
usepackage{tikz}
usetikzlibrary{hobby}
begin{document}
begin{tikzpicture}[scale=.6,cap=round,
tangent/.style={%
in angle={(180+#1)} ,
Hobby finish ,
designated Hobby path=next , out angle=#1,
}]
tikzset{axes/.style={}}
% The graphic
begin{scope}[style=axes]
draw[->] (-5,0) -- (5,0) node[below] {$x$};
draw[->] (0,-3)-- (0,5) node[left] {$y$};
%draw [gray!50] (-5,3) -- (-2.5,1) -- (2.5,4) -- (5,-1);
draw [red,thick,<->,use Hobby shortcut]
([tangent=-80]-5,4) .. (-2.5,1) .. (2.5,4) .. ([tangent=-80]5,-1);
end{scope}
end{tikzpicture}
end{document}


enter image description here



Does this come closer to what you want to achieve?



ADDENDUM: You are asking about the distortion you get when you add or remove an arrow. The effect you are referring to is clearly visible as the difference between the red and blue curves in



documentclass{article}
usepackage{tikz}
%usetikzlibrary{bending}
begin{document}
begin{tikzpicture}[scale=.6,cap=round]
tikzset{axes/.style={}}
% The graphic
begin{scope}[style=axes]
draw[->] (-5,0) -- (5,0) node[below] {$x$};
draw[->] (0,-3)-- (0,5) node[left] {$y$};
%draw [gray!50] (-5,3) -- (-2.5,1) -- (2.5,4) -- (5,-1);
draw [red,thick,<->] plot [smooth,tension=1] coordinates {
(-5,4) (-2.5,1) (2.5,4) (5,-1)};
draw [blue,thick,-] plot [smooth,tension=1] coordinates {
(-5,4) (-2.5,1) (2.5,4) (5,-1)};
end{scope}
end{tikzpicture}
end{document}


enter image description here



This effect is due to the fact that a (standard) arrow inserts a stretch of straight (as opposed to curved) path. You can simply get rid of it by activating usetikzlibrary{bending}, i.e. by removing the % in front of it.



enter image description here



Of course, if you have longer arrows, you want to make sure that you load arrows.meta as well and pass bend to the options of the arrow, e.g. `



 draw [red,thick,{Latex[bend,length=5pt]}-{Latex[bend,length=5pt]}] plot [smooth,tension=1] coordinates { 
(-5,4) (-2.5,1) (2.5,4) (5,-1)};





share|improve this answer























  • Thanks Marmot, this output is what I need. Again the program I posted works without end arrows, but this Hobby library is new to me as well!
    – MathScholar
    Nov 15 at 12:23

















up vote
5
down vote



accepted










I do not precisely understand what you mean by "Why do the arrows ruin the left side but keep the right side smooth? ". However, this is just to say that there are many possible ways to draw smooth curves with TikZ. A rather powerful way is to employ the hobby library.



documentclass{article}
usepackage{tikz}
usetikzlibrary{hobby}
begin{document}
begin{tikzpicture}[scale=.6,cap=round,
tangent/.style={%
in angle={(180+#1)} ,
Hobby finish ,
designated Hobby path=next , out angle=#1,
}]
tikzset{axes/.style={}}
% The graphic
begin{scope}[style=axes]
draw[->] (-5,0) -- (5,0) node[below] {$x$};
draw[->] (0,-3)-- (0,5) node[left] {$y$};
%draw [gray!50] (-5,3) -- (-2.5,1) -- (2.5,4) -- (5,-1);
draw [red,thick,<->,use Hobby shortcut]
([tangent=-80]-5,4) .. (-2.5,1) .. (2.5,4) .. ([tangent=-80]5,-1);
end{scope}
end{tikzpicture}
end{document}


enter image description here



Does this come closer to what you want to achieve?



ADDENDUM: You are asking about the distortion you get when you add or remove an arrow. The effect you are referring to is clearly visible as the difference between the red and blue curves in



documentclass{article}
usepackage{tikz}
%usetikzlibrary{bending}
begin{document}
begin{tikzpicture}[scale=.6,cap=round]
tikzset{axes/.style={}}
% The graphic
begin{scope}[style=axes]
draw[->] (-5,0) -- (5,0) node[below] {$x$};
draw[->] (0,-3)-- (0,5) node[left] {$y$};
%draw [gray!50] (-5,3) -- (-2.5,1) -- (2.5,4) -- (5,-1);
draw [red,thick,<->] plot [smooth,tension=1] coordinates {
(-5,4) (-2.5,1) (2.5,4) (5,-1)};
draw [blue,thick,-] plot [smooth,tension=1] coordinates {
(-5,4) (-2.5,1) (2.5,4) (5,-1)};
end{scope}
end{tikzpicture}
end{document}


enter image description here



This effect is due to the fact that a (standard) arrow inserts a stretch of straight (as opposed to curved) path. You can simply get rid of it by activating usetikzlibrary{bending}, i.e. by removing the % in front of it.



enter image description here



Of course, if you have longer arrows, you want to make sure that you load arrows.meta as well and pass bend to the options of the arrow, e.g. `



 draw [red,thick,{Latex[bend,length=5pt]}-{Latex[bend,length=5pt]}] plot [smooth,tension=1] coordinates { 
(-5,4) (-2.5,1) (2.5,4) (5,-1)};





share|improve this answer























  • Thanks Marmot, this output is what I need. Again the program I posted works without end arrows, but this Hobby library is new to me as well!
    – MathScholar
    Nov 15 at 12:23















up vote
5
down vote



accepted







up vote
5
down vote



accepted






I do not precisely understand what you mean by "Why do the arrows ruin the left side but keep the right side smooth? ". However, this is just to say that there are many possible ways to draw smooth curves with TikZ. A rather powerful way is to employ the hobby library.



documentclass{article}
usepackage{tikz}
usetikzlibrary{hobby}
begin{document}
begin{tikzpicture}[scale=.6,cap=round,
tangent/.style={%
in angle={(180+#1)} ,
Hobby finish ,
designated Hobby path=next , out angle=#1,
}]
tikzset{axes/.style={}}
% The graphic
begin{scope}[style=axes]
draw[->] (-5,0) -- (5,0) node[below] {$x$};
draw[->] (0,-3)-- (0,5) node[left] {$y$};
%draw [gray!50] (-5,3) -- (-2.5,1) -- (2.5,4) -- (5,-1);
draw [red,thick,<->,use Hobby shortcut]
([tangent=-80]-5,4) .. (-2.5,1) .. (2.5,4) .. ([tangent=-80]5,-1);
end{scope}
end{tikzpicture}
end{document}


enter image description here



Does this come closer to what you want to achieve?



ADDENDUM: You are asking about the distortion you get when you add or remove an arrow. The effect you are referring to is clearly visible as the difference between the red and blue curves in



documentclass{article}
usepackage{tikz}
%usetikzlibrary{bending}
begin{document}
begin{tikzpicture}[scale=.6,cap=round]
tikzset{axes/.style={}}
% The graphic
begin{scope}[style=axes]
draw[->] (-5,0) -- (5,0) node[below] {$x$};
draw[->] (0,-3)-- (0,5) node[left] {$y$};
%draw [gray!50] (-5,3) -- (-2.5,1) -- (2.5,4) -- (5,-1);
draw [red,thick,<->] plot [smooth,tension=1] coordinates {
(-5,4) (-2.5,1) (2.5,4) (5,-1)};
draw [blue,thick,-] plot [smooth,tension=1] coordinates {
(-5,4) (-2.5,1) (2.5,4) (5,-1)};
end{scope}
end{tikzpicture}
end{document}


enter image description here



This effect is due to the fact that a (standard) arrow inserts a stretch of straight (as opposed to curved) path. You can simply get rid of it by activating usetikzlibrary{bending}, i.e. by removing the % in front of it.



enter image description here



Of course, if you have longer arrows, you want to make sure that you load arrows.meta as well and pass bend to the options of the arrow, e.g. `



 draw [red,thick,{Latex[bend,length=5pt]}-{Latex[bend,length=5pt]}] plot [smooth,tension=1] coordinates { 
(-5,4) (-2.5,1) (2.5,4) (5,-1)};





share|improve this answer














I do not precisely understand what you mean by "Why do the arrows ruin the left side but keep the right side smooth? ". However, this is just to say that there are many possible ways to draw smooth curves with TikZ. A rather powerful way is to employ the hobby library.



documentclass{article}
usepackage{tikz}
usetikzlibrary{hobby}
begin{document}
begin{tikzpicture}[scale=.6,cap=round,
tangent/.style={%
in angle={(180+#1)} ,
Hobby finish ,
designated Hobby path=next , out angle=#1,
}]
tikzset{axes/.style={}}
% The graphic
begin{scope}[style=axes]
draw[->] (-5,0) -- (5,0) node[below] {$x$};
draw[->] (0,-3)-- (0,5) node[left] {$y$};
%draw [gray!50] (-5,3) -- (-2.5,1) -- (2.5,4) -- (5,-1);
draw [red,thick,<->,use Hobby shortcut]
([tangent=-80]-5,4) .. (-2.5,1) .. (2.5,4) .. ([tangent=-80]5,-1);
end{scope}
end{tikzpicture}
end{document}


enter image description here



Does this come closer to what you want to achieve?



ADDENDUM: You are asking about the distortion you get when you add or remove an arrow. The effect you are referring to is clearly visible as the difference between the red and blue curves in



documentclass{article}
usepackage{tikz}
%usetikzlibrary{bending}
begin{document}
begin{tikzpicture}[scale=.6,cap=round]
tikzset{axes/.style={}}
% The graphic
begin{scope}[style=axes]
draw[->] (-5,0) -- (5,0) node[below] {$x$};
draw[->] (0,-3)-- (0,5) node[left] {$y$};
%draw [gray!50] (-5,3) -- (-2.5,1) -- (2.5,4) -- (5,-1);
draw [red,thick,<->] plot [smooth,tension=1] coordinates {
(-5,4) (-2.5,1) (2.5,4) (5,-1)};
draw [blue,thick,-] plot [smooth,tension=1] coordinates {
(-5,4) (-2.5,1) (2.5,4) (5,-1)};
end{scope}
end{tikzpicture}
end{document}


enter image description here



This effect is due to the fact that a (standard) arrow inserts a stretch of straight (as opposed to curved) path. You can simply get rid of it by activating usetikzlibrary{bending}, i.e. by removing the % in front of it.



enter image description here



Of course, if you have longer arrows, you want to make sure that you load arrows.meta as well and pass bend to the options of the arrow, e.g. `



 draw [red,thick,{Latex[bend,length=5pt]}-{Latex[bend,length=5pt]}] plot [smooth,tension=1] coordinates { 
(-5,4) (-2.5,1) (2.5,4) (5,-1)};






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 15 at 14:55

























answered Nov 15 at 4:47









marmot

78.4k487166




78.4k487166












  • Thanks Marmot, this output is what I need. Again the program I posted works without end arrows, but this Hobby library is new to me as well!
    – MathScholar
    Nov 15 at 12:23




















  • Thanks Marmot, this output is what I need. Again the program I posted works without end arrows, but this Hobby library is new to me as well!
    – MathScholar
    Nov 15 at 12:23


















Thanks Marmot, this output is what I need. Again the program I posted works without end arrows, but this Hobby library is new to me as well!
– MathScholar
Nov 15 at 12:23






Thanks Marmot, this output is what I need. Again the program I posted works without end arrows, but this Hobby library is new to me as well!
– MathScholar
Nov 15 at 12:23




















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f460058%2farbitrary-curve-in-tikz%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Plaza Victoria

In PowerPoint, is there a keyboard shortcut for bulleted / numbered list?

How to put 3 figures in Latex with 2 figures side by side and 1 below these side by side images but in...