Arbitrary Curve in Tikz











up vote
6
down vote

favorite
2












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
    10 hours ago












  • I see. I expanded my answer by adding a explanation why that happens, hand how it can be prevented.
    – marmot
    7 hours ago















up vote
6
down vote

favorite
2












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
    10 hours ago












  • I see. I expanded my answer by adding a explanation why that happens, hand how it can be prevented.
    – marmot
    7 hours ago













up vote
6
down vote

favorite
2









up vote
6
down vote

favorite
2






2





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 17 hours ago









MathScholar

3128




3128












  • @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
    10 hours ago












  • I see. I expanded my answer by adding a explanation why that happens, hand how it can be prevented.
    – marmot
    7 hours ago


















  • @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
    10 hours ago












  • I see. I expanded my answer by adding a explanation why that happens, hand how it can be prevented.
    – marmot
    7 hours ago
















@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
10 hours ago






@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
10 hours ago














I see. I expanded my answer by adding a explanation why that happens, hand how it can be prevented.
– marmot
7 hours ago




I see. I expanded my answer by adding a explanation why that happens, hand how it can be prevented.
– marmot
7 hours ago










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
    9 hours ago













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
    9 hours ago

















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
    9 hours ago















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 7 hours ago

























answered 17 hours ago









marmot

75.1k485159




75.1k485159












  • 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
    9 hours ago




















  • 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
    9 hours ago


















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
9 hours ago






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
9 hours ago




















 

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

QoS: MAC-Priority for clients behind a repeater

Ивакино (Тотемский район)

Can't locate Autom4te/ChannelDefs.pm in @INC (when it definitely is there)