Arbitrary Curve in Tikz

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











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.



documentclassarticle
usepackagetikz
begindocument
begintikzpicture[scale=.6,cap=round]
tikzsetaxes/.style=
% The graphic
beginscope[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);
endscope
endtikzpicture
enddocument


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
    yesterday











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










  • @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
    yesterday














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.



documentclassarticle
usepackagetikz
begindocument
begintikzpicture[scale=.6,cap=round]
tikzsetaxes/.style=
% The graphic
beginscope[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);
endscope
endtikzpicture
enddocument


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
    yesterday











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










  • @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
    yesterday












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.



documentclassarticle
usepackagetikz
begindocument
begintikzpicture[scale=.6,cap=round]
tikzsetaxes/.style=
% The graphic
beginscope[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);
endscope
endtikzpicture
enddocument


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.



documentclassarticle
usepackagetikz
begindocument
begintikzpicture[scale=.6,cap=round]
tikzsetaxes/.style=
% The graphic
beginscope[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);
endscope
endtikzpicture
enddocument


enter image description here







tikz-pgf






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked yesterday









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
    yesterday











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










  • @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
    yesterday
















  • @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
    yesterday











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










  • @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
    yesterday















@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
yesterday





@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
yesterday













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




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












@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
yesterday




@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
yesterday










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.



documentclassarticle
usepackagetikz
usetikzlibraryhobby
begindocument
begintikzpicture[scale=.6,cap=round,
tangent/.style=%
in angle=(180+#1) ,
Hobby finish ,
designated Hobby path=next , out angle=#1,
]
tikzsetaxes/.style=
% The graphic
beginscope[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);
endscope
endtikzpicture
enddocument


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



documentclassarticle
usepackagetikz
%usetikzlibrarybending
begindocument
begintikzpicture[scale=.6,cap=round]
tikzsetaxes/.style=
% The graphic
beginscope[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);
endscope
endtikzpicture
enddocument


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 usetikzlibrarybending, 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
    yesterday











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.



documentclassarticle
usepackagetikz
usetikzlibraryhobby
begindocument
begintikzpicture[scale=.6,cap=round,
tangent/.style=%
in angle=(180+#1) ,
Hobby finish ,
designated Hobby path=next , out angle=#1,
]
tikzsetaxes/.style=
% The graphic
beginscope[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);
endscope
endtikzpicture
enddocument


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



documentclassarticle
usepackagetikz
%usetikzlibrarybending
begindocument
begintikzpicture[scale=.6,cap=round]
tikzsetaxes/.style=
% The graphic
beginscope[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);
endscope
endtikzpicture
enddocument


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 usetikzlibrarybending, 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
    yesterday















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.



documentclassarticle
usepackagetikz
usetikzlibraryhobby
begindocument
begintikzpicture[scale=.6,cap=round,
tangent/.style=%
in angle=(180+#1) ,
Hobby finish ,
designated Hobby path=next , out angle=#1,
]
tikzsetaxes/.style=
% The graphic
beginscope[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);
endscope
endtikzpicture
enddocument


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



documentclassarticle
usepackagetikz
%usetikzlibrarybending
begindocument
begintikzpicture[scale=.6,cap=round]
tikzsetaxes/.style=
% The graphic
beginscope[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);
endscope
endtikzpicture
enddocument


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 usetikzlibrarybending, 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
    yesterday













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.



documentclassarticle
usepackagetikz
usetikzlibraryhobby
begindocument
begintikzpicture[scale=.6,cap=round,
tangent/.style=%
in angle=(180+#1) ,
Hobby finish ,
designated Hobby path=next , out angle=#1,
]
tikzsetaxes/.style=
% The graphic
beginscope[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);
endscope
endtikzpicture
enddocument


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



documentclassarticle
usepackagetikz
%usetikzlibrarybending
begindocument
begintikzpicture[scale=.6,cap=round]
tikzsetaxes/.style=
% The graphic
beginscope[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);
endscope
endtikzpicture
enddocument


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 usetikzlibrarybending, 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.



documentclassarticle
usepackagetikz
usetikzlibraryhobby
begindocument
begintikzpicture[scale=.6,cap=round,
tangent/.style=%
in angle=(180+#1) ,
Hobby finish ,
designated Hobby path=next , out angle=#1,
]
tikzsetaxes/.style=
% The graphic
beginscope[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);
endscope
endtikzpicture
enddocument


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



documentclassarticle
usepackagetikz
%usetikzlibrarybending
begindocument
begintikzpicture[scale=.6,cap=round]
tikzsetaxes/.style=
% The graphic
beginscope[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);
endscope
endtikzpicture
enddocument


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 usetikzlibrarybending, 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 yesterday

























answered yesterday









marmot

75.4k485159




75.4k485159











  • 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
    yesterday

















  • 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
    yesterday
















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
yesterday





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
yesterday


















 

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

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay