Arbitrary Curve in Tikz
up vote
6
down vote
favorite
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}
tikz-pgf
add a comment |
up vote
6
down vote
favorite
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}
tikz-pgf
@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
add a comment |
up vote
6
down vote
favorite
up vote
6
down vote
favorite
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}
tikz-pgf
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}
tikz-pgf
tikz-pgf
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
add a comment |
@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
add a comment |
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}
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}
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.
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)};
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
add a comment |
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}
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}
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.
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)};
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
add a comment |
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}
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}
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.
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)};
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
add a comment |
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}
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}
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.
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)};
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}
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}
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.
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)};
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
add a comment |
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
add a comment |
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%2f460058%2farbitrary-curve-in-tikz%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
@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