tikz - how to bend straight lines in a graph
Clash Royale CLAN TAG#URR8PPP
up vote
3
down vote
favorite
So I'm trying to plot a graph with routes. I have two questions:
- How can I bend the lines? I would like the 9->4 to go around node 7.
- How can I change the names of the nodes? I want node 9 to be called "0".
Is the method I chose to simple to make these changes?
begintikzpicture[scale=.1,vertex/.style=draw,circle, arc/.style=draw,thick,->]
foreach [count=i] coord in (40,30),(90,10),(20,70),(100,20),(90,20),(70,30),(70,40),(10,70),(50,50)
node[vertex] (pi) at coord i;
foreach [count=r] row in 0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0
foreach [count=c] cell in row
ifnumcell=1%
draw[arc] (pr) edge (pc);
fi
endtikzpicture
tikz-pgf
New contributor
Anon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
up vote
3
down vote
favorite
So I'm trying to plot a graph with routes. I have two questions:
- How can I bend the lines? I would like the 9->4 to go around node 7.
- How can I change the names of the nodes? I want node 9 to be called "0".
Is the method I chose to simple to make these changes?
begintikzpicture[scale=.1,vertex/.style=draw,circle, arc/.style=draw,thick,->]
foreach [count=i] coord in (40,30),(90,10),(20,70),(100,20),(90,20),(70,30),(70,40),(10,70),(50,50)
node[vertex] (pi) at coord i;
foreach [count=r] row in 0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0
foreach [count=c] cell in row
ifnumcell=1%
draw[arc] (pr) edge (pc);
fi
endtikzpicture
tikz-pgf
New contributor
Anon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
Welcome to Tex StackExchange. See also this question for instance.
– Karlo
2 hours ago
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
So I'm trying to plot a graph with routes. I have two questions:
- How can I bend the lines? I would like the 9->4 to go around node 7.
- How can I change the names of the nodes? I want node 9 to be called "0".
Is the method I chose to simple to make these changes?
begintikzpicture[scale=.1,vertex/.style=draw,circle, arc/.style=draw,thick,->]
foreach [count=i] coord in (40,30),(90,10),(20,70),(100,20),(90,20),(70,30),(70,40),(10,70),(50,50)
node[vertex] (pi) at coord i;
foreach [count=r] row in 0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0
foreach [count=c] cell in row
ifnumcell=1%
draw[arc] (pr) edge (pc);
fi
endtikzpicture
tikz-pgf
New contributor
Anon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
So I'm trying to plot a graph with routes. I have two questions:
- How can I bend the lines? I would like the 9->4 to go around node 7.
- How can I change the names of the nodes? I want node 9 to be called "0".
Is the method I chose to simple to make these changes?
begintikzpicture[scale=.1,vertex/.style=draw,circle, arc/.style=draw,thick,->]
foreach [count=i] coord in (40,30),(90,10),(20,70),(100,20),(90,20),(70,30),(70,40),(10,70),(50,50)
node[vertex] (pi) at coord i;
foreach [count=r] row in 0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0
foreach [count=c] cell in row
ifnumcell=1%
draw[arc] (pr) edge (pc);
fi
endtikzpicture
tikz-pgf
tikz-pgf
New contributor
Anon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Anon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Anon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 2 hours ago


Anon
182
182
New contributor
Anon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Anon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Anon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
Welcome to Tex StackExchange. See also this question for instance.
– Karlo
2 hours ago
add a comment |Â
1
Welcome to Tex StackExchange. See also this question for instance.
– Karlo
2 hours ago
1
1
Welcome to Tex StackExchange. See also this question for instance.
– Karlo
2 hours ago
Welcome to Tex StackExchange. See also this question for instance.
– Karlo
2 hours ago
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
4
down vote
accepted
Welcome to TeX.SE! I had to rescale your coordinates to avoid dimension too large
errors, yet the graph looks as if I had not done that.
documentclass[tikz,border=3.14mm]standalone
begindocument
begintikzpicture[vertex/.style=draw,circle, arc/.style=draw,thick,->]
foreach [count=i] coord in (4,3),(9,1),(2,7),(10,2),(9,2),(7,3),(7,4),(1,7),(5,5)
ifnumi=9
node[vertex,alias=p0] (pi) at coord 0;
else
node[vertex] (pi) at coord i;
fi
foreach [count=r] row in 0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0
foreach [count=c] cell in row
ifnumcell=1%
ifnumr>c
pgfmathtruncatemacroitestr+c*10
ifnumitest=49
draw[arc] (pr) edge[bend left] (pc);
else
draw[arc] (pr) edge (pc);
fi
else
draw[arc] (pr) edge (pc);
fi
fi
endtikzpicture
enddocument
add a comment |Â
up vote
1
down vote
I coded your figure in a simpler way using the native possibilities of the foreach
loop and the chains
library.
It is possible to make only one loop: the one that defines the nodes. To make node 9 (5,5)
named 0, simply place it at the beginning of the foreach and start the count at zero.
foreach coord [count=i from 0] in (5,5),(4,3),(9,1),(2,7),(10,2),(9,2),(7,3),(7,4),(1,7)
node[vertex] (pi) at coord i;
Then with the chains library to connect the nodes with arrows.
documentclass[tikz,border=5mm]standalone
usetikzlibrarychains
begindocument
begintikzpicture[start chain,scale=1,vertex/.style=draw,circle, every join/.style=draw,thick,->]
foreach coord [count=i from 0] in (5,5),(4,3),(9,1),(2,7),(10,2),(9,2),(7,3),(7,4),(1,7)
node[vertex] (pi) at coord i;
chainin (p0);
chainin (p8)[join];
chainin (p3)[join];
chainin (p1)[join];
chainin (p0)[join];
chainin (p4)[join=with p0 by bend left];
chainin (p2)[join];
chainin (p5)[join];
chainin (p6)[join];
chainin (p7)[join];
chainin (p0)[join];
endtikzpicture
enddocument
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
accepted
Welcome to TeX.SE! I had to rescale your coordinates to avoid dimension too large
errors, yet the graph looks as if I had not done that.
documentclass[tikz,border=3.14mm]standalone
begindocument
begintikzpicture[vertex/.style=draw,circle, arc/.style=draw,thick,->]
foreach [count=i] coord in (4,3),(9,1),(2,7),(10,2),(9,2),(7,3),(7,4),(1,7),(5,5)
ifnumi=9
node[vertex,alias=p0] (pi) at coord 0;
else
node[vertex] (pi) at coord i;
fi
foreach [count=r] row in 0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0
foreach [count=c] cell in row
ifnumcell=1%
ifnumr>c
pgfmathtruncatemacroitestr+c*10
ifnumitest=49
draw[arc] (pr) edge[bend left] (pc);
else
draw[arc] (pr) edge (pc);
fi
else
draw[arc] (pr) edge (pc);
fi
fi
endtikzpicture
enddocument
add a comment |Â
up vote
4
down vote
accepted
Welcome to TeX.SE! I had to rescale your coordinates to avoid dimension too large
errors, yet the graph looks as if I had not done that.
documentclass[tikz,border=3.14mm]standalone
begindocument
begintikzpicture[vertex/.style=draw,circle, arc/.style=draw,thick,->]
foreach [count=i] coord in (4,3),(9,1),(2,7),(10,2),(9,2),(7,3),(7,4),(1,7),(5,5)
ifnumi=9
node[vertex,alias=p0] (pi) at coord 0;
else
node[vertex] (pi) at coord i;
fi
foreach [count=r] row in 0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0
foreach [count=c] cell in row
ifnumcell=1%
ifnumr>c
pgfmathtruncatemacroitestr+c*10
ifnumitest=49
draw[arc] (pr) edge[bend left] (pc);
else
draw[arc] (pr) edge (pc);
fi
else
draw[arc] (pr) edge (pc);
fi
fi
endtikzpicture
enddocument
add a comment |Â
up vote
4
down vote
accepted
up vote
4
down vote
accepted
Welcome to TeX.SE! I had to rescale your coordinates to avoid dimension too large
errors, yet the graph looks as if I had not done that.
documentclass[tikz,border=3.14mm]standalone
begindocument
begintikzpicture[vertex/.style=draw,circle, arc/.style=draw,thick,->]
foreach [count=i] coord in (4,3),(9,1),(2,7),(10,2),(9,2),(7,3),(7,4),(1,7),(5,5)
ifnumi=9
node[vertex,alias=p0] (pi) at coord 0;
else
node[vertex] (pi) at coord i;
fi
foreach [count=r] row in 0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0
foreach [count=c] cell in row
ifnumcell=1%
ifnumr>c
pgfmathtruncatemacroitestr+c*10
ifnumitest=49
draw[arc] (pr) edge[bend left] (pc);
else
draw[arc] (pr) edge (pc);
fi
else
draw[arc] (pr) edge (pc);
fi
fi
endtikzpicture
enddocument
Welcome to TeX.SE! I had to rescale your coordinates to avoid dimension too large
errors, yet the graph looks as if I had not done that.
documentclass[tikz,border=3.14mm]standalone
begindocument
begintikzpicture[vertex/.style=draw,circle, arc/.style=draw,thick,->]
foreach [count=i] coord in (4,3),(9,1),(2,7),(10,2),(9,2),(7,3),(7,4),(1,7),(5,5)
ifnumi=9
node[vertex,alias=p0] (pi) at coord 0;
else
node[vertex] (pi) at coord i;
fi
foreach [count=r] row in 0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0
foreach [count=c] cell in row
ifnumcell=1%
ifnumr>c
pgfmathtruncatemacroitestr+c*10
ifnumitest=49
draw[arc] (pr) edge[bend left] (pc);
else
draw[arc] (pr) edge (pc);
fi
else
draw[arc] (pr) edge (pc);
fi
fi
endtikzpicture
enddocument
answered 2 hours ago


marmot
68k475147
68k475147
add a comment |Â
add a comment |Â
up vote
1
down vote
I coded your figure in a simpler way using the native possibilities of the foreach
loop and the chains
library.
It is possible to make only one loop: the one that defines the nodes. To make node 9 (5,5)
named 0, simply place it at the beginning of the foreach and start the count at zero.
foreach coord [count=i from 0] in (5,5),(4,3),(9,1),(2,7),(10,2),(9,2),(7,3),(7,4),(1,7)
node[vertex] (pi) at coord i;
Then with the chains library to connect the nodes with arrows.
documentclass[tikz,border=5mm]standalone
usetikzlibrarychains
begindocument
begintikzpicture[start chain,scale=1,vertex/.style=draw,circle, every join/.style=draw,thick,->]
foreach coord [count=i from 0] in (5,5),(4,3),(9,1),(2,7),(10,2),(9,2),(7,3),(7,4),(1,7)
node[vertex] (pi) at coord i;
chainin (p0);
chainin (p8)[join];
chainin (p3)[join];
chainin (p1)[join];
chainin (p0)[join];
chainin (p4)[join=with p0 by bend left];
chainin (p2)[join];
chainin (p5)[join];
chainin (p6)[join];
chainin (p7)[join];
chainin (p0)[join];
endtikzpicture
enddocument
add a comment |Â
up vote
1
down vote
I coded your figure in a simpler way using the native possibilities of the foreach
loop and the chains
library.
It is possible to make only one loop: the one that defines the nodes. To make node 9 (5,5)
named 0, simply place it at the beginning of the foreach and start the count at zero.
foreach coord [count=i from 0] in (5,5),(4,3),(9,1),(2,7),(10,2),(9,2),(7,3),(7,4),(1,7)
node[vertex] (pi) at coord i;
Then with the chains library to connect the nodes with arrows.
documentclass[tikz,border=5mm]standalone
usetikzlibrarychains
begindocument
begintikzpicture[start chain,scale=1,vertex/.style=draw,circle, every join/.style=draw,thick,->]
foreach coord [count=i from 0] in (5,5),(4,3),(9,1),(2,7),(10,2),(9,2),(7,3),(7,4),(1,7)
node[vertex] (pi) at coord i;
chainin (p0);
chainin (p8)[join];
chainin (p3)[join];
chainin (p1)[join];
chainin (p0)[join];
chainin (p4)[join=with p0 by bend left];
chainin (p2)[join];
chainin (p5)[join];
chainin (p6)[join];
chainin (p7)[join];
chainin (p0)[join];
endtikzpicture
enddocument
add a comment |Â
up vote
1
down vote
up vote
1
down vote
I coded your figure in a simpler way using the native possibilities of the foreach
loop and the chains
library.
It is possible to make only one loop: the one that defines the nodes. To make node 9 (5,5)
named 0, simply place it at the beginning of the foreach and start the count at zero.
foreach coord [count=i from 0] in (5,5),(4,3),(9,1),(2,7),(10,2),(9,2),(7,3),(7,4),(1,7)
node[vertex] (pi) at coord i;
Then with the chains library to connect the nodes with arrows.
documentclass[tikz,border=5mm]standalone
usetikzlibrarychains
begindocument
begintikzpicture[start chain,scale=1,vertex/.style=draw,circle, every join/.style=draw,thick,->]
foreach coord [count=i from 0] in (5,5),(4,3),(9,1),(2,7),(10,2),(9,2),(7,3),(7,4),(1,7)
node[vertex] (pi) at coord i;
chainin (p0);
chainin (p8)[join];
chainin (p3)[join];
chainin (p1)[join];
chainin (p0)[join];
chainin (p4)[join=with p0 by bend left];
chainin (p2)[join];
chainin (p5)[join];
chainin (p6)[join];
chainin (p7)[join];
chainin (p0)[join];
endtikzpicture
enddocument
I coded your figure in a simpler way using the native possibilities of the foreach
loop and the chains
library.
It is possible to make only one loop: the one that defines the nodes. To make node 9 (5,5)
named 0, simply place it at the beginning of the foreach and start the count at zero.
foreach coord [count=i from 0] in (5,5),(4,3),(9,1),(2,7),(10,2),(9,2),(7,3),(7,4),(1,7)
node[vertex] (pi) at coord i;
Then with the chains library to connect the nodes with arrows.
documentclass[tikz,border=5mm]standalone
usetikzlibrarychains
begindocument
begintikzpicture[start chain,scale=1,vertex/.style=draw,circle, every join/.style=draw,thick,->]
foreach coord [count=i from 0] in (5,5),(4,3),(9,1),(2,7),(10,2),(9,2),(7,3),(7,4),(1,7)
node[vertex] (pi) at coord i;
chainin (p0);
chainin (p8)[join];
chainin (p3)[join];
chainin (p1)[join];
chainin (p0)[join];
chainin (p4)[join=with p0 by bend left];
chainin (p2)[join];
chainin (p5)[join];
chainin (p6)[join];
chainin (p7)[join];
chainin (p0)[join];
endtikzpicture
enddocument
answered 17 mins ago
AndréC
4,002832
4,002832
add a comment |Â
add a comment |Â
Anon is a new contributor. Be nice, and check out our Code of Conduct.
Anon is a new contributor. Be nice, and check out our Code of Conduct.
Anon is a new contributor. Be nice, and check out our Code of Conduct.
Anon is a new contributor. Be nice, and check out our Code of Conduct.
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f456525%2ftikz-how-to-bend-straight-lines-in-a-graph%23new-answer', 'question_page');
);
Post as a guest
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
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
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
1
Welcome to Tex StackExchange. See also this question for instance.
– Karlo
2 hours ago