Drawing arrow between plots (table datas)

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











up vote
3
down vote

favorite












I use pfgplots to draw two sets of data, stored in .dat. Now I would like to automatically draw an arrow from one curve to the other, and only at the curves points. I tried to name the paths, but to no avail... Here is my minimum working example:



documentclass[11pt]standalone
usepackagetikz,pgfplots,filecontents
pgfplotssetcompat=newest
usepgfplotslibraryfillbetween
beginfilecontents*data1.dat
a b
1 1
2 1.2
3 1.5
endfilecontents*
beginfilecontents*data2.dat
a b
1 1.5
2 1.75
3 1.6
endfilecontents*

begindocument
begintikzpicture
%graphique
beginaxis
addplot[name path=c1,blue,thick,mark=*] plot table[x=a,y=b]data1.dat;
addplot[name path=c2,black,thick,mark=*] plot table[x=a,y=b]data2.dat;
%draw[red,->] (c1) -- (c2);

endaxis
endtikzpicture

enddocument


Which gives:
example output



I would like to get (automatically from data points):
desired output



To generate this last picture I defined each arrow separately, for example for the last arrow:
draw[red,-latex,thick,shorten >=0.1em] (3,1.5) -- (3,1.6);



I tryed to use the fillbetween package to name the paths, but I have not been able to use it so far. Could I get something like : draw[red,->] (c1) -- (c2); ?



Thanks a lot for your help!










share|improve this question





















  • So you are searching for something similar to tex.stackexchange.com/a/385766/95441, right? Are you able to adjust this solution on your own?
    – Stefan Pinnow
    56 mins ago











  • Yes thanks a lot! I did see this post, maybe because I got to much focussed on putting "arrow" in my research... I came up with a solution thanks to you, I am going to post it
    – jeannej
    37 mins ago














up vote
3
down vote

favorite












I use pfgplots to draw two sets of data, stored in .dat. Now I would like to automatically draw an arrow from one curve to the other, and only at the curves points. I tried to name the paths, but to no avail... Here is my minimum working example:



documentclass[11pt]standalone
usepackagetikz,pgfplots,filecontents
pgfplotssetcompat=newest
usepgfplotslibraryfillbetween
beginfilecontents*data1.dat
a b
1 1
2 1.2
3 1.5
endfilecontents*
beginfilecontents*data2.dat
a b
1 1.5
2 1.75
3 1.6
endfilecontents*

begindocument
begintikzpicture
%graphique
beginaxis
addplot[name path=c1,blue,thick,mark=*] plot table[x=a,y=b]data1.dat;
addplot[name path=c2,black,thick,mark=*] plot table[x=a,y=b]data2.dat;
%draw[red,->] (c1) -- (c2);

endaxis
endtikzpicture

enddocument


Which gives:
example output



I would like to get (automatically from data points):
desired output



To generate this last picture I defined each arrow separately, for example for the last arrow:
draw[red,-latex,thick,shorten >=0.1em] (3,1.5) -- (3,1.6);



I tryed to use the fillbetween package to name the paths, but I have not been able to use it so far. Could I get something like : draw[red,->] (c1) -- (c2); ?



Thanks a lot for your help!










share|improve this question





















  • So you are searching for something similar to tex.stackexchange.com/a/385766/95441, right? Are you able to adjust this solution on your own?
    – Stefan Pinnow
    56 mins ago











  • Yes thanks a lot! I did see this post, maybe because I got to much focussed on putting "arrow" in my research... I came up with a solution thanks to you, I am going to post it
    – jeannej
    37 mins ago












up vote
3
down vote

favorite









up vote
3
down vote

favorite











I use pfgplots to draw two sets of data, stored in .dat. Now I would like to automatically draw an arrow from one curve to the other, and only at the curves points. I tried to name the paths, but to no avail... Here is my minimum working example:



documentclass[11pt]standalone
usepackagetikz,pgfplots,filecontents
pgfplotssetcompat=newest
usepgfplotslibraryfillbetween
beginfilecontents*data1.dat
a b
1 1
2 1.2
3 1.5
endfilecontents*
beginfilecontents*data2.dat
a b
1 1.5
2 1.75
3 1.6
endfilecontents*

begindocument
begintikzpicture
%graphique
beginaxis
addplot[name path=c1,blue,thick,mark=*] plot table[x=a,y=b]data1.dat;
addplot[name path=c2,black,thick,mark=*] plot table[x=a,y=b]data2.dat;
%draw[red,->] (c1) -- (c2);

endaxis
endtikzpicture

enddocument


Which gives:
example output



I would like to get (automatically from data points):
desired output



To generate this last picture I defined each arrow separately, for example for the last arrow:
draw[red,-latex,thick,shorten >=0.1em] (3,1.5) -- (3,1.6);



I tryed to use the fillbetween package to name the paths, but I have not been able to use it so far. Could I get something like : draw[red,->] (c1) -- (c2); ?



Thanks a lot for your help!










share|improve this question













I use pfgplots to draw two sets of data, stored in .dat. Now I would like to automatically draw an arrow from one curve to the other, and only at the curves points. I tried to name the paths, but to no avail... Here is my minimum working example:



documentclass[11pt]standalone
usepackagetikz,pgfplots,filecontents
pgfplotssetcompat=newest
usepgfplotslibraryfillbetween
beginfilecontents*data1.dat
a b
1 1
2 1.2
3 1.5
endfilecontents*
beginfilecontents*data2.dat
a b
1 1.5
2 1.75
3 1.6
endfilecontents*

begindocument
begintikzpicture
%graphique
beginaxis
addplot[name path=c1,blue,thick,mark=*] plot table[x=a,y=b]data1.dat;
addplot[name path=c2,black,thick,mark=*] plot table[x=a,y=b]data2.dat;
%draw[red,->] (c1) -- (c2);

endaxis
endtikzpicture

enddocument


Which gives:
example output



I would like to get (automatically from data points):
desired output



To generate this last picture I defined each arrow separately, for example for the last arrow:
draw[red,-latex,thick,shorten >=0.1em] (3,1.5) -- (3,1.6);



I tryed to use the fillbetween package to name the paths, but I have not been able to use it so far. Could I get something like : draw[red,->] (c1) -- (c2); ?



Thanks a lot for your help!







tikz-pgf pgfplots arrows tikz-datavisualization






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 1 hour ago









jeannej

465




465











  • So you are searching for something similar to tex.stackexchange.com/a/385766/95441, right? Are you able to adjust this solution on your own?
    – Stefan Pinnow
    56 mins ago











  • Yes thanks a lot! I did see this post, maybe because I got to much focussed on putting "arrow" in my research... I came up with a solution thanks to you, I am going to post it
    – jeannej
    37 mins ago
















  • So you are searching for something similar to tex.stackexchange.com/a/385766/95441, right? Are you able to adjust this solution on your own?
    – Stefan Pinnow
    56 mins ago











  • Yes thanks a lot! I did see this post, maybe because I got to much focussed on putting "arrow" in my research... I came up with a solution thanks to you, I am going to post it
    – jeannej
    37 mins ago















So you are searching for something similar to tex.stackexchange.com/a/385766/95441, right? Are you able to adjust this solution on your own?
– Stefan Pinnow
56 mins ago





So you are searching for something similar to tex.stackexchange.com/a/385766/95441, right? Are you able to adjust this solution on your own?
– Stefan Pinnow
56 mins ago













Yes thanks a lot! I did see this post, maybe because I got to much focussed on putting "arrow" in my research... I came up with a solution thanks to you, I am going to post it
– jeannej
37 mins ago




Yes thanks a lot! I did see this post, maybe because I got to much focussed on putting "arrow" in my research... I came up with a solution thanks to you, I am going to post it
– jeannej
37 mins ago










2 Answers
2






active

oldest

votes

















up vote
3
down vote













Here is an alternative based on this nice answer. Its advantage is that it does not rely on the plot points having always the same distance. In fact, in your data set they don't, and that's the reason why in your answer the middle arrow is not vertical.



documentclass[11pt]standalone
usepackagetikz,pgfplots,filecontents
pgfplotssetcompat=newest
usepgfplotslibraryfillbetween
beginfilecontents*data1.dat
a b
1 1
2 1.2
3 1.5
endfilecontents*
beginfilecontents*data2.dat
a b
1 1.5
2 1.75
3 1.6
endfilecontents*

pgfplotsset
name nodes near coords/.style=
every node near coord/.append style=
name=#1-coordindex,
alias=#1-last,
,
,
name nodes near coords/.default=coordnode


begindocument

begintikzpicture

beginaxis[
nodes near coords=,nodes near coords style=anchor=center
]
addplot[blue,thick,mark=*, name nodes near coords=c]
table[x=a,y=b]data1.dat;
addplot+[black,thick,mark=*, name nodes near coords=d] table[x=a,y=b]data2.dat;
endaxis
foreach X in 0,...,2
draw[red,latex-latex] (c-X) -- (d-X);
endtikzpicture
enddocument


enter image description here






share|improve this answer




















  • If you want the arrows to "touch" the plot marks, use nodes near coords style=anchor=center,inner sep=2pt instead of nodes near coords style=anchor=center.
    – marmot
    16 mins ago

















up vote
2
down vote













Thanks to this previous post, I came up with this solution.



documentclass[11pt]standalone
usepackagetikz,pgfplots
pgfplotssetcompat=newest

beginfilecontents*data1.dat
a b
1 1
2 1.2
3 1.5
endfilecontents*
beginfilecontents*data2.dat
a b
1 1.5
2 1.75
3 1.6
endfilecontents*

%reads data
pgfplotstablereaddata1.datdataA %beware that "data1" would trigger an error => do not use numbers
pgfplotstablegetrowsofdataA
pgfmathtruncatemacroNpgfplotsretval-1 %get access to the number of points in data

begindocument
begintikzpicture
%graphique
beginaxis
addplot[blue,thick,mark=*] plot table[x=a,y=b]data1.dat
foreach i in 0,...,N coordinate [pos=i/N] (ai);
addplot[black,thick,mark=*] plot table[x=a,y=b]data2.dat
foreach i in 0,...,N coordinate [pos=i/N] (bi);
endaxis
foreach i in 0,...,N
draw[red,-latex,thick,shorten >=0.1em] (ai) -- (bi);

endtikzpicture

enddocument


Which gives:
solution1



However you'll notice a slight shift of my middle arrow. I think this comes from my data not being evenly distributed... Would you have any insight on this ?






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: 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%2f458871%2fdrawing-arrow-between-plots-table-datas%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
    3
    down vote













    Here is an alternative based on this nice answer. Its advantage is that it does not rely on the plot points having always the same distance. In fact, in your data set they don't, and that's the reason why in your answer the middle arrow is not vertical.



    documentclass[11pt]standalone
    usepackagetikz,pgfplots,filecontents
    pgfplotssetcompat=newest
    usepgfplotslibraryfillbetween
    beginfilecontents*data1.dat
    a b
    1 1
    2 1.2
    3 1.5
    endfilecontents*
    beginfilecontents*data2.dat
    a b
    1 1.5
    2 1.75
    3 1.6
    endfilecontents*

    pgfplotsset
    name nodes near coords/.style=
    every node near coord/.append style=
    name=#1-coordindex,
    alias=#1-last,
    ,
    ,
    name nodes near coords/.default=coordnode


    begindocument

    begintikzpicture

    beginaxis[
    nodes near coords=,nodes near coords style=anchor=center
    ]
    addplot[blue,thick,mark=*, name nodes near coords=c]
    table[x=a,y=b]data1.dat;
    addplot+[black,thick,mark=*, name nodes near coords=d] table[x=a,y=b]data2.dat;
    endaxis
    foreach X in 0,...,2
    draw[red,latex-latex] (c-X) -- (d-X);
    endtikzpicture
    enddocument


    enter image description here






    share|improve this answer




















    • If you want the arrows to "touch" the plot marks, use nodes near coords style=anchor=center,inner sep=2pt instead of nodes near coords style=anchor=center.
      – marmot
      16 mins ago














    up vote
    3
    down vote













    Here is an alternative based on this nice answer. Its advantage is that it does not rely on the plot points having always the same distance. In fact, in your data set they don't, and that's the reason why in your answer the middle arrow is not vertical.



    documentclass[11pt]standalone
    usepackagetikz,pgfplots,filecontents
    pgfplotssetcompat=newest
    usepgfplotslibraryfillbetween
    beginfilecontents*data1.dat
    a b
    1 1
    2 1.2
    3 1.5
    endfilecontents*
    beginfilecontents*data2.dat
    a b
    1 1.5
    2 1.75
    3 1.6
    endfilecontents*

    pgfplotsset
    name nodes near coords/.style=
    every node near coord/.append style=
    name=#1-coordindex,
    alias=#1-last,
    ,
    ,
    name nodes near coords/.default=coordnode


    begindocument

    begintikzpicture

    beginaxis[
    nodes near coords=,nodes near coords style=anchor=center
    ]
    addplot[blue,thick,mark=*, name nodes near coords=c]
    table[x=a,y=b]data1.dat;
    addplot+[black,thick,mark=*, name nodes near coords=d] table[x=a,y=b]data2.dat;
    endaxis
    foreach X in 0,...,2
    draw[red,latex-latex] (c-X) -- (d-X);
    endtikzpicture
    enddocument


    enter image description here






    share|improve this answer




















    • If you want the arrows to "touch" the plot marks, use nodes near coords style=anchor=center,inner sep=2pt instead of nodes near coords style=anchor=center.
      – marmot
      16 mins ago












    up vote
    3
    down vote










    up vote
    3
    down vote









    Here is an alternative based on this nice answer. Its advantage is that it does not rely on the plot points having always the same distance. In fact, in your data set they don't, and that's the reason why in your answer the middle arrow is not vertical.



    documentclass[11pt]standalone
    usepackagetikz,pgfplots,filecontents
    pgfplotssetcompat=newest
    usepgfplotslibraryfillbetween
    beginfilecontents*data1.dat
    a b
    1 1
    2 1.2
    3 1.5
    endfilecontents*
    beginfilecontents*data2.dat
    a b
    1 1.5
    2 1.75
    3 1.6
    endfilecontents*

    pgfplotsset
    name nodes near coords/.style=
    every node near coord/.append style=
    name=#1-coordindex,
    alias=#1-last,
    ,
    ,
    name nodes near coords/.default=coordnode


    begindocument

    begintikzpicture

    beginaxis[
    nodes near coords=,nodes near coords style=anchor=center
    ]
    addplot[blue,thick,mark=*, name nodes near coords=c]
    table[x=a,y=b]data1.dat;
    addplot+[black,thick,mark=*, name nodes near coords=d] table[x=a,y=b]data2.dat;
    endaxis
    foreach X in 0,...,2
    draw[red,latex-latex] (c-X) -- (d-X);
    endtikzpicture
    enddocument


    enter image description here






    share|improve this answer












    Here is an alternative based on this nice answer. Its advantage is that it does not rely on the plot points having always the same distance. In fact, in your data set they don't, and that's the reason why in your answer the middle arrow is not vertical.



    documentclass[11pt]standalone
    usepackagetikz,pgfplots,filecontents
    pgfplotssetcompat=newest
    usepgfplotslibraryfillbetween
    beginfilecontents*data1.dat
    a b
    1 1
    2 1.2
    3 1.5
    endfilecontents*
    beginfilecontents*data2.dat
    a b
    1 1.5
    2 1.75
    3 1.6
    endfilecontents*

    pgfplotsset
    name nodes near coords/.style=
    every node near coord/.append style=
    name=#1-coordindex,
    alias=#1-last,
    ,
    ,
    name nodes near coords/.default=coordnode


    begindocument

    begintikzpicture

    beginaxis[
    nodes near coords=,nodes near coords style=anchor=center
    ]
    addplot[blue,thick,mark=*, name nodes near coords=c]
    table[x=a,y=b]data1.dat;
    addplot+[black,thick,mark=*, name nodes near coords=d] table[x=a,y=b]data2.dat;
    endaxis
    foreach X in 0,...,2
    draw[red,latex-latex] (c-X) -- (d-X);
    endtikzpicture
    enddocument


    enter image description here







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered 17 mins ago









    marmot

    72.4k477153




    72.4k477153











    • If you want the arrows to "touch" the plot marks, use nodes near coords style=anchor=center,inner sep=2pt instead of nodes near coords style=anchor=center.
      – marmot
      16 mins ago
















    • If you want the arrows to "touch" the plot marks, use nodes near coords style=anchor=center,inner sep=2pt instead of nodes near coords style=anchor=center.
      – marmot
      16 mins ago















    If you want the arrows to "touch" the plot marks, use nodes near coords style=anchor=center,inner sep=2pt instead of nodes near coords style=anchor=center.
    – marmot
    16 mins ago




    If you want the arrows to "touch" the plot marks, use nodes near coords style=anchor=center,inner sep=2pt instead of nodes near coords style=anchor=center.
    – marmot
    16 mins ago










    up vote
    2
    down vote













    Thanks to this previous post, I came up with this solution.



    documentclass[11pt]standalone
    usepackagetikz,pgfplots
    pgfplotssetcompat=newest

    beginfilecontents*data1.dat
    a b
    1 1
    2 1.2
    3 1.5
    endfilecontents*
    beginfilecontents*data2.dat
    a b
    1 1.5
    2 1.75
    3 1.6
    endfilecontents*

    %reads data
    pgfplotstablereaddata1.datdataA %beware that "data1" would trigger an error => do not use numbers
    pgfplotstablegetrowsofdataA
    pgfmathtruncatemacroNpgfplotsretval-1 %get access to the number of points in data

    begindocument
    begintikzpicture
    %graphique
    beginaxis
    addplot[blue,thick,mark=*] plot table[x=a,y=b]data1.dat
    foreach i in 0,...,N coordinate [pos=i/N] (ai);
    addplot[black,thick,mark=*] plot table[x=a,y=b]data2.dat
    foreach i in 0,...,N coordinate [pos=i/N] (bi);
    endaxis
    foreach i in 0,...,N
    draw[red,-latex,thick,shorten >=0.1em] (ai) -- (bi);

    endtikzpicture

    enddocument


    Which gives:
    solution1



    However you'll notice a slight shift of my middle arrow. I think this comes from my data not being evenly distributed... Would you have any insight on this ?






    share|improve this answer
























      up vote
      2
      down vote













      Thanks to this previous post, I came up with this solution.



      documentclass[11pt]standalone
      usepackagetikz,pgfplots
      pgfplotssetcompat=newest

      beginfilecontents*data1.dat
      a b
      1 1
      2 1.2
      3 1.5
      endfilecontents*
      beginfilecontents*data2.dat
      a b
      1 1.5
      2 1.75
      3 1.6
      endfilecontents*

      %reads data
      pgfplotstablereaddata1.datdataA %beware that "data1" would trigger an error => do not use numbers
      pgfplotstablegetrowsofdataA
      pgfmathtruncatemacroNpgfplotsretval-1 %get access to the number of points in data

      begindocument
      begintikzpicture
      %graphique
      beginaxis
      addplot[blue,thick,mark=*] plot table[x=a,y=b]data1.dat
      foreach i in 0,...,N coordinate [pos=i/N] (ai);
      addplot[black,thick,mark=*] plot table[x=a,y=b]data2.dat
      foreach i in 0,...,N coordinate [pos=i/N] (bi);
      endaxis
      foreach i in 0,...,N
      draw[red,-latex,thick,shorten >=0.1em] (ai) -- (bi);

      endtikzpicture

      enddocument


      Which gives:
      solution1



      However you'll notice a slight shift of my middle arrow. I think this comes from my data not being evenly distributed... Would you have any insight on this ?






      share|improve this answer






















        up vote
        2
        down vote










        up vote
        2
        down vote









        Thanks to this previous post, I came up with this solution.



        documentclass[11pt]standalone
        usepackagetikz,pgfplots
        pgfplotssetcompat=newest

        beginfilecontents*data1.dat
        a b
        1 1
        2 1.2
        3 1.5
        endfilecontents*
        beginfilecontents*data2.dat
        a b
        1 1.5
        2 1.75
        3 1.6
        endfilecontents*

        %reads data
        pgfplotstablereaddata1.datdataA %beware that "data1" would trigger an error => do not use numbers
        pgfplotstablegetrowsofdataA
        pgfmathtruncatemacroNpgfplotsretval-1 %get access to the number of points in data

        begindocument
        begintikzpicture
        %graphique
        beginaxis
        addplot[blue,thick,mark=*] plot table[x=a,y=b]data1.dat
        foreach i in 0,...,N coordinate [pos=i/N] (ai);
        addplot[black,thick,mark=*] plot table[x=a,y=b]data2.dat
        foreach i in 0,...,N coordinate [pos=i/N] (bi);
        endaxis
        foreach i in 0,...,N
        draw[red,-latex,thick,shorten >=0.1em] (ai) -- (bi);

        endtikzpicture

        enddocument


        Which gives:
        solution1



        However you'll notice a slight shift of my middle arrow. I think this comes from my data not being evenly distributed... Would you have any insight on this ?






        share|improve this answer












        Thanks to this previous post, I came up with this solution.



        documentclass[11pt]standalone
        usepackagetikz,pgfplots
        pgfplotssetcompat=newest

        beginfilecontents*data1.dat
        a b
        1 1
        2 1.2
        3 1.5
        endfilecontents*
        beginfilecontents*data2.dat
        a b
        1 1.5
        2 1.75
        3 1.6
        endfilecontents*

        %reads data
        pgfplotstablereaddata1.datdataA %beware that "data1" would trigger an error => do not use numbers
        pgfplotstablegetrowsofdataA
        pgfmathtruncatemacroNpgfplotsretval-1 %get access to the number of points in data

        begindocument
        begintikzpicture
        %graphique
        beginaxis
        addplot[blue,thick,mark=*] plot table[x=a,y=b]data1.dat
        foreach i in 0,...,N coordinate [pos=i/N] (ai);
        addplot[black,thick,mark=*] plot table[x=a,y=b]data2.dat
        foreach i in 0,...,N coordinate [pos=i/N] (bi);
        endaxis
        foreach i in 0,...,N
        draw[red,-latex,thick,shorten >=0.1em] (ai) -- (bi);

        endtikzpicture

        enddocument


        Which gives:
        solution1



        However you'll notice a slight shift of my middle arrow. I think this comes from my data not being evenly distributed... Would you have any insight on this ?







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 27 mins ago









        jeannej

        465




        465



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f458871%2fdrawing-arrow-between-plots-table-datas%23new-answer', 'question_page');

            );

            Post as a guest













































































            Comments

            Popular posts from this blog

            What does second last employer means? [closed]

            Installing NextGIS Connect into QGIS 3?

            One-line joke