tikz - how to bend straight lines in a graph

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











up vote
3
down vote

favorite












enter image description here



So I'm trying to plot a graph with routes. I have two questions:



  1. How can I bend the lines? I would like the 9->4 to go around node 7.

  2. 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









share|improve this question







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














up vote
3
down vote

favorite












enter image description here



So I'm trying to plot a graph with routes. I have two questions:



  1. How can I bend the lines? I would like the 9->4 to go around node 7.

  2. 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









share|improve this question







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












up vote
3
down vote

favorite









up vote
3
down vote

favorite











enter image description here



So I'm trying to plot a graph with routes. I have two questions:



  1. How can I bend the lines? I would like the 9->4 to go around node 7.

  2. 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









share|improve this question







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.











enter image description here



So I'm trying to plot a graph with routes. I have two questions:



  1. How can I bend the lines? I would like the 9->4 to go around node 7.

  2. 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






share|improve this question







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.











share|improve this question







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.









share|improve this question




share|improve this question






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












  • 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










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


enter image description here






share|improve this answer



























    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


    chaine






    share|improve this answer




















      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: false,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );






      Anon is a new contributor. Be nice, and check out our Code of Conduct.









       

      draft saved


      draft discarded


















      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






























      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


      enter image description here






      share|improve this answer
























        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


        enter image description here






        share|improve this answer






















          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


          enter image description here






          share|improve this answer












          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


          enter image description here







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 2 hours ago









          marmot

          68k475147




          68k475147




















              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


              chaine






              share|improve this answer
























                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


                chaine






                share|improve this answer






















                  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


                  chaine






                  share|improve this answer












                  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


                  chaine







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 17 mins ago









                  AndréC

                  4,002832




                  4,002832




















                      Anon is a new contributor. Be nice, and check out our Code of Conduct.









                       

                      draft saved


                      draft discarded


















                      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.













                       


                      draft saved


                      draft discarded














                      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













































































                      Comments

                      Popular posts from this blog

                      What does second last employer means? [closed]

                      List of Gilmore Girls characters

                      Confectionery