How to plot data from a CSV file using tikz and csvsimple?











up vote
39
down vote

favorite
19












Here is a minimal example :



begin{filecontents*}{data.csv}
a,b,c,d
1,4,5,1
2,3,1,5
3,5,6,1
4,1,4,9
5,3,4,7
end{filecontents*}

documentclass{article}
usepackage[utf8]{inputenc}
usepackage{csvsimple}
usepackage{tikz}

begin{document}
begin{tikzpicture}
draw plot coordinates {%
csvreader[head to column names]{data.csv}{}{(a,b) }
};
end{tikzpicture}
end{document}


The command csvreader[head to column names]{data.csv}{}{(a,b) } extracts coordinates (columns a and c) from the CSV file data.csv :



(1,4) (2,3) (3,5) (4,1) (5,3)


And yet, it seems that I can't plot the points above using tikz :



Package tikz Error: Cannot parse this coordinate


Any idea ?










share|improve this question
























  • Why simple way when there is complex methods? May be this answer -- tex.stackexchange.com/a/83740/11232 is useful (that uses pgfplotstable)
    – user11232
    Nov 23 '12 at 2:17










  • I don't see any data printed with csvsimple package. Can you make it work if you use it outside the TikZ picture?
    – percusse
    Nov 23 '12 at 3:16










  • begin{tikzpicture} csvreader[head to column names]{data.csv}{}{% draw (a,b) node {$times$}; } end{tikzpicture} will work but I need to draw segments, not points. So I need a way to remember the previous point like in the csvsimple examples (not hard, but I don't know LaTeX that well).
    – remjg
    Nov 23 '12 at 11:11












  • @HarishKumar I had a look at it, but I had so much trouble getting use to csvsimple... So I don't want to use an other package now ;-)
    – remjg
    Nov 23 '12 at 11:32















up vote
39
down vote

favorite
19












Here is a minimal example :



begin{filecontents*}{data.csv}
a,b,c,d
1,4,5,1
2,3,1,5
3,5,6,1
4,1,4,9
5,3,4,7
end{filecontents*}

documentclass{article}
usepackage[utf8]{inputenc}
usepackage{csvsimple}
usepackage{tikz}

begin{document}
begin{tikzpicture}
draw plot coordinates {%
csvreader[head to column names]{data.csv}{}{(a,b) }
};
end{tikzpicture}
end{document}


The command csvreader[head to column names]{data.csv}{}{(a,b) } extracts coordinates (columns a and c) from the CSV file data.csv :



(1,4) (2,3) (3,5) (4,1) (5,3)


And yet, it seems that I can't plot the points above using tikz :



Package tikz Error: Cannot parse this coordinate


Any idea ?










share|improve this question
























  • Why simple way when there is complex methods? May be this answer -- tex.stackexchange.com/a/83740/11232 is useful (that uses pgfplotstable)
    – user11232
    Nov 23 '12 at 2:17










  • I don't see any data printed with csvsimple package. Can you make it work if you use it outside the TikZ picture?
    – percusse
    Nov 23 '12 at 3:16










  • begin{tikzpicture} csvreader[head to column names]{data.csv}{}{% draw (a,b) node {$times$}; } end{tikzpicture} will work but I need to draw segments, not points. So I need a way to remember the previous point like in the csvsimple examples (not hard, but I don't know LaTeX that well).
    – remjg
    Nov 23 '12 at 11:11












  • @HarishKumar I had a look at it, but I had so much trouble getting use to csvsimple... So I don't want to use an other package now ;-)
    – remjg
    Nov 23 '12 at 11:32













up vote
39
down vote

favorite
19









up vote
39
down vote

favorite
19






19





Here is a minimal example :



begin{filecontents*}{data.csv}
a,b,c,d
1,4,5,1
2,3,1,5
3,5,6,1
4,1,4,9
5,3,4,7
end{filecontents*}

documentclass{article}
usepackage[utf8]{inputenc}
usepackage{csvsimple}
usepackage{tikz}

begin{document}
begin{tikzpicture}
draw plot coordinates {%
csvreader[head to column names]{data.csv}{}{(a,b) }
};
end{tikzpicture}
end{document}


The command csvreader[head to column names]{data.csv}{}{(a,b) } extracts coordinates (columns a and c) from the CSV file data.csv :



(1,4) (2,3) (3,5) (4,1) (5,3)


And yet, it seems that I can't plot the points above using tikz :



Package tikz Error: Cannot parse this coordinate


Any idea ?










share|improve this question















Here is a minimal example :



begin{filecontents*}{data.csv}
a,b,c,d
1,4,5,1
2,3,1,5
3,5,6,1
4,1,4,9
5,3,4,7
end{filecontents*}

documentclass{article}
usepackage[utf8]{inputenc}
usepackage{csvsimple}
usepackage{tikz}

begin{document}
begin{tikzpicture}
draw plot coordinates {%
csvreader[head to column names]{data.csv}{}{(a,b) }
};
end{tikzpicture}
end{document}


The command csvreader[head to column names]{data.csv}{}{(a,b) } extracts coordinates (columns a and c) from the CSV file data.csv :



(1,4) (2,3) (3,5) (4,1) (5,3)


And yet, it seems that I can't plot the points above using tikz :



Package tikz Error: Cannot parse this coordinate


Any idea ?







tikz-pgf pgfplots plot csv csvsimple






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 7 '14 at 5:40









Thomas F. Sturm

19.2k13171




19.2k13171










asked Nov 23 '12 at 1:41









remjg

1,2562923




1,2562923












  • Why simple way when there is complex methods? May be this answer -- tex.stackexchange.com/a/83740/11232 is useful (that uses pgfplotstable)
    – user11232
    Nov 23 '12 at 2:17










  • I don't see any data printed with csvsimple package. Can you make it work if you use it outside the TikZ picture?
    – percusse
    Nov 23 '12 at 3:16










  • begin{tikzpicture} csvreader[head to column names]{data.csv}{}{% draw (a,b) node {$times$}; } end{tikzpicture} will work but I need to draw segments, not points. So I need a way to remember the previous point like in the csvsimple examples (not hard, but I don't know LaTeX that well).
    – remjg
    Nov 23 '12 at 11:11












  • @HarishKumar I had a look at it, but I had so much trouble getting use to csvsimple... So I don't want to use an other package now ;-)
    – remjg
    Nov 23 '12 at 11:32


















  • Why simple way when there is complex methods? May be this answer -- tex.stackexchange.com/a/83740/11232 is useful (that uses pgfplotstable)
    – user11232
    Nov 23 '12 at 2:17










  • I don't see any data printed with csvsimple package. Can you make it work if you use it outside the TikZ picture?
    – percusse
    Nov 23 '12 at 3:16










  • begin{tikzpicture} csvreader[head to column names]{data.csv}{}{% draw (a,b) node {$times$}; } end{tikzpicture} will work but I need to draw segments, not points. So I need a way to remember the previous point like in the csvsimple examples (not hard, but I don't know LaTeX that well).
    – remjg
    Nov 23 '12 at 11:11












  • @HarishKumar I had a look at it, but I had so much trouble getting use to csvsimple... So I don't want to use an other package now ;-)
    – remjg
    Nov 23 '12 at 11:32
















Why simple way when there is complex methods? May be this answer -- tex.stackexchange.com/a/83740/11232 is useful (that uses pgfplotstable)
– user11232
Nov 23 '12 at 2:17




Why simple way when there is complex methods? May be this answer -- tex.stackexchange.com/a/83740/11232 is useful (that uses pgfplotstable)
– user11232
Nov 23 '12 at 2:17












I don't see any data printed with csvsimple package. Can you make it work if you use it outside the TikZ picture?
– percusse
Nov 23 '12 at 3:16




I don't see any data printed with csvsimple package. Can you make it work if you use it outside the TikZ picture?
– percusse
Nov 23 '12 at 3:16












begin{tikzpicture} csvreader[head to column names]{data.csv}{}{% draw (a,b) node {$times$}; } end{tikzpicture} will work but I need to draw segments, not points. So I need a way to remember the previous point like in the csvsimple examples (not hard, but I don't know LaTeX that well).
– remjg
Nov 23 '12 at 11:11






begin{tikzpicture} csvreader[head to column names]{data.csv}{}{% draw (a,b) node {$times$}; } end{tikzpicture} will work but I need to draw segments, not points. So I need a way to remember the previous point like in the csvsimple examples (not hard, but I don't know LaTeX that well).
– remjg
Nov 23 '12 at 11:11














@HarishKumar I had a look at it, but I had so much trouble getting use to csvsimple... So I don't want to use an other package now ;-)
– remjg
Nov 23 '12 at 11:32




@HarishKumar I had a look at it, but I had so much trouble getting use to csvsimple... So I don't want to use an other package now ;-)
– remjg
Nov 23 '12 at 11:32










3 Answers
3






active

oldest

votes

















up vote
51
down vote



accepted










If you need to plot data from files, I think you'll be much happier if you use PGFPlots instead of the native plot functionality of TikZ. Here's a very simple example of plotting your example data to get you started.



PGFPlots is very customizable, you can tweak virtually every aspect of your plots, and it's much more user-friendly than if you tried to knit everything yourself.





documentclass{article}
usepackage{pgfplots}
usepackage{filecontents}
begin{filecontents*}{data.csv}
a,b,c,d
1,4,5,1
2,3,1,5
3,5,6,1
4,1,4,9
5,3,4,7
end{filecontents*}


begin{document}
begin{tikzpicture}
begin{axis}
addplot table [x=a, y=c, col sep=comma] {data.csv};
end{axis}
end{tikzpicture}
end{document}





share|improve this answer



















  • 1




    Indeed, it's pretty straightforward. I'll try today !
    – remjg
    Nov 23 '12 at 12:16










  • @RémiG.: Good decision =). If you have questions, don't hesitate to post them on the site, there are plenty of people with lots of PGFPlots expertise around here.
    – Jake
    Nov 23 '12 at 12:19










  • I still face an issue. The same potion of code doesn't work inside a macro : File ended while scanning use of pgfplots@addplotimpl@table@fromfile. Maybe I should ask another question...
    – remjg
    Nov 23 '12 at 12:39






  • 2




    So I needed to add shorthandoff{;} inside the tikzpicture environment to avoid problem with [frenchb]babel. The solution is explained here : tex.stackexchange.com/questions/74860/…. I'm all good now, thank you for your help !
    – remjg
    Nov 23 '12 at 14:20








  • 6




    Shouldn't y=c be y=b here? Otherwise I can't see the relation between the code and the shown plot.
    – eightx2
    May 1 '15 at 16:26


















up vote
7
down vote













It seems that it's impossible to call csvreader inside draw plot coordinates { }. To avoid the plot command and still being able to plot lines between points, I need to use xdef to remember the previous point.



begin{filecontents*}{data.csv}
a,b,c,d
1,4,5,1
2,3,1,5
3,5,6,1
4,1,4,9
5,3,4,7
end{filecontents*}

documentclass{article}
usepackage[utf8]{inputenc}
usepackage{csvsimple}
usepackage{tikz}

begin{document}
begin{tikzpicture}
csvreader[ head to column names,%
late after head=xdefaold{a}xdefbold{b},%
after line=xdefaold{a}xdefbold{b}]%
{data.csv}{}{%
draw (aold, bold) -- (a,b) node {$times$};
}
end{tikzpicture}
end{document}


I get the output below. Now I can get back to work and print a whole bunch of data in my report ;-) I love it !



Plot of CSV data using <code>tikz</code> and <code>csvsimple</code>






share|improve this answer






























    up vote
    2
    down vote













    Another example with csvsimple, tikz and pgf-pie.



    begin{filecontents*}{newData.csv}
    20,30,50
    end{filecontents*}

    documentclass[10pt,a4paper]{article}
    usepackage[utf8]{inputenc}

    usepackage{csvsimple}
    usepackage{tikz}
    usepackage{pgf-pie}

    begin{document}

    begin{tikzpicture}
    csvreader[no head]%
    {newData.csv}
    {1=colVali,2=colValii,3=colValiii}
    {%
    pie[polar, explode=0.1]
    {colVali/A, colValii/B, colValiii/C}
    }
    end{tikzpicture}

    end{document}


    Which produces the following pie chart:



    enter image description here






    share|improve this answer








    New contributor




    Mab is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.


















      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%2f83888%2fhow-to-plot-data-from-a-csv-file-using-tikz-and-csvsimple%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      51
      down vote



      accepted










      If you need to plot data from files, I think you'll be much happier if you use PGFPlots instead of the native plot functionality of TikZ. Here's a very simple example of plotting your example data to get you started.



      PGFPlots is very customizable, you can tweak virtually every aspect of your plots, and it's much more user-friendly than if you tried to knit everything yourself.





      documentclass{article}
      usepackage{pgfplots}
      usepackage{filecontents}
      begin{filecontents*}{data.csv}
      a,b,c,d
      1,4,5,1
      2,3,1,5
      3,5,6,1
      4,1,4,9
      5,3,4,7
      end{filecontents*}


      begin{document}
      begin{tikzpicture}
      begin{axis}
      addplot table [x=a, y=c, col sep=comma] {data.csv};
      end{axis}
      end{tikzpicture}
      end{document}





      share|improve this answer



















      • 1




        Indeed, it's pretty straightforward. I'll try today !
        – remjg
        Nov 23 '12 at 12:16










      • @RémiG.: Good decision =). If you have questions, don't hesitate to post them on the site, there are plenty of people with lots of PGFPlots expertise around here.
        – Jake
        Nov 23 '12 at 12:19










      • I still face an issue. The same potion of code doesn't work inside a macro : File ended while scanning use of pgfplots@addplotimpl@table@fromfile. Maybe I should ask another question...
        – remjg
        Nov 23 '12 at 12:39






      • 2




        So I needed to add shorthandoff{;} inside the tikzpicture environment to avoid problem with [frenchb]babel. The solution is explained here : tex.stackexchange.com/questions/74860/…. I'm all good now, thank you for your help !
        – remjg
        Nov 23 '12 at 14:20








      • 6




        Shouldn't y=c be y=b here? Otherwise I can't see the relation between the code and the shown plot.
        – eightx2
        May 1 '15 at 16:26















      up vote
      51
      down vote



      accepted










      If you need to plot data from files, I think you'll be much happier if you use PGFPlots instead of the native plot functionality of TikZ. Here's a very simple example of plotting your example data to get you started.



      PGFPlots is very customizable, you can tweak virtually every aspect of your plots, and it's much more user-friendly than if you tried to knit everything yourself.





      documentclass{article}
      usepackage{pgfplots}
      usepackage{filecontents}
      begin{filecontents*}{data.csv}
      a,b,c,d
      1,4,5,1
      2,3,1,5
      3,5,6,1
      4,1,4,9
      5,3,4,7
      end{filecontents*}


      begin{document}
      begin{tikzpicture}
      begin{axis}
      addplot table [x=a, y=c, col sep=comma] {data.csv};
      end{axis}
      end{tikzpicture}
      end{document}





      share|improve this answer



















      • 1




        Indeed, it's pretty straightforward. I'll try today !
        – remjg
        Nov 23 '12 at 12:16










      • @RémiG.: Good decision =). If you have questions, don't hesitate to post them on the site, there are plenty of people with lots of PGFPlots expertise around here.
        – Jake
        Nov 23 '12 at 12:19










      • I still face an issue. The same potion of code doesn't work inside a macro : File ended while scanning use of pgfplots@addplotimpl@table@fromfile. Maybe I should ask another question...
        – remjg
        Nov 23 '12 at 12:39






      • 2




        So I needed to add shorthandoff{;} inside the tikzpicture environment to avoid problem with [frenchb]babel. The solution is explained here : tex.stackexchange.com/questions/74860/…. I'm all good now, thank you for your help !
        – remjg
        Nov 23 '12 at 14:20








      • 6




        Shouldn't y=c be y=b here? Otherwise I can't see the relation between the code and the shown plot.
        – eightx2
        May 1 '15 at 16:26













      up vote
      51
      down vote



      accepted







      up vote
      51
      down vote



      accepted






      If you need to plot data from files, I think you'll be much happier if you use PGFPlots instead of the native plot functionality of TikZ. Here's a very simple example of plotting your example data to get you started.



      PGFPlots is very customizable, you can tweak virtually every aspect of your plots, and it's much more user-friendly than if you tried to knit everything yourself.





      documentclass{article}
      usepackage{pgfplots}
      usepackage{filecontents}
      begin{filecontents*}{data.csv}
      a,b,c,d
      1,4,5,1
      2,3,1,5
      3,5,6,1
      4,1,4,9
      5,3,4,7
      end{filecontents*}


      begin{document}
      begin{tikzpicture}
      begin{axis}
      addplot table [x=a, y=c, col sep=comma] {data.csv};
      end{axis}
      end{tikzpicture}
      end{document}





      share|improve this answer














      If you need to plot data from files, I think you'll be much happier if you use PGFPlots instead of the native plot functionality of TikZ. Here's a very simple example of plotting your example data to get you started.



      PGFPlots is very customizable, you can tweak virtually every aspect of your plots, and it's much more user-friendly than if you tried to knit everything yourself.





      documentclass{article}
      usepackage{pgfplots}
      usepackage{filecontents}
      begin{filecontents*}{data.csv}
      a,b,c,d
      1,4,5,1
      2,3,1,5
      3,5,6,1
      4,1,4,9
      5,3,4,7
      end{filecontents*}


      begin{document}
      begin{tikzpicture}
      begin{axis}
      addplot table [x=a, y=c, col sep=comma] {data.csv};
      end{axis}
      end{tikzpicture}
      end{document}






      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Nov 23 '12 at 12:24









      remjg

      1,2562923




      1,2562923










      answered Nov 23 '12 at 11:56









      Jake

      192k23639757




      192k23639757








      • 1




        Indeed, it's pretty straightforward. I'll try today !
        – remjg
        Nov 23 '12 at 12:16










      • @RémiG.: Good decision =). If you have questions, don't hesitate to post them on the site, there are plenty of people with lots of PGFPlots expertise around here.
        – Jake
        Nov 23 '12 at 12:19










      • I still face an issue. The same potion of code doesn't work inside a macro : File ended while scanning use of pgfplots@addplotimpl@table@fromfile. Maybe I should ask another question...
        – remjg
        Nov 23 '12 at 12:39






      • 2




        So I needed to add shorthandoff{;} inside the tikzpicture environment to avoid problem with [frenchb]babel. The solution is explained here : tex.stackexchange.com/questions/74860/…. I'm all good now, thank you for your help !
        – remjg
        Nov 23 '12 at 14:20








      • 6




        Shouldn't y=c be y=b here? Otherwise I can't see the relation between the code and the shown plot.
        – eightx2
        May 1 '15 at 16:26














      • 1




        Indeed, it's pretty straightforward. I'll try today !
        – remjg
        Nov 23 '12 at 12:16










      • @RémiG.: Good decision =). If you have questions, don't hesitate to post them on the site, there are plenty of people with lots of PGFPlots expertise around here.
        – Jake
        Nov 23 '12 at 12:19










      • I still face an issue. The same potion of code doesn't work inside a macro : File ended while scanning use of pgfplots@addplotimpl@table@fromfile. Maybe I should ask another question...
        – remjg
        Nov 23 '12 at 12:39






      • 2




        So I needed to add shorthandoff{;} inside the tikzpicture environment to avoid problem with [frenchb]babel. The solution is explained here : tex.stackexchange.com/questions/74860/…. I'm all good now, thank you for your help !
        – remjg
        Nov 23 '12 at 14:20








      • 6




        Shouldn't y=c be y=b here? Otherwise I can't see the relation between the code and the shown plot.
        – eightx2
        May 1 '15 at 16:26








      1




      1




      Indeed, it's pretty straightforward. I'll try today !
      – remjg
      Nov 23 '12 at 12:16




      Indeed, it's pretty straightforward. I'll try today !
      – remjg
      Nov 23 '12 at 12:16












      @RémiG.: Good decision =). If you have questions, don't hesitate to post them on the site, there are plenty of people with lots of PGFPlots expertise around here.
      – Jake
      Nov 23 '12 at 12:19




      @RémiG.: Good decision =). If you have questions, don't hesitate to post them on the site, there are plenty of people with lots of PGFPlots expertise around here.
      – Jake
      Nov 23 '12 at 12:19












      I still face an issue. The same potion of code doesn't work inside a macro : File ended while scanning use of pgfplots@addplotimpl@table@fromfile. Maybe I should ask another question...
      – remjg
      Nov 23 '12 at 12:39




      I still face an issue. The same potion of code doesn't work inside a macro : File ended while scanning use of pgfplots@addplotimpl@table@fromfile. Maybe I should ask another question...
      – remjg
      Nov 23 '12 at 12:39




      2




      2




      So I needed to add shorthandoff{;} inside the tikzpicture environment to avoid problem with [frenchb]babel. The solution is explained here : tex.stackexchange.com/questions/74860/…. I'm all good now, thank you for your help !
      – remjg
      Nov 23 '12 at 14:20






      So I needed to add shorthandoff{;} inside the tikzpicture environment to avoid problem with [frenchb]babel. The solution is explained here : tex.stackexchange.com/questions/74860/…. I'm all good now, thank you for your help !
      – remjg
      Nov 23 '12 at 14:20






      6




      6




      Shouldn't y=c be y=b here? Otherwise I can't see the relation between the code and the shown plot.
      – eightx2
      May 1 '15 at 16:26




      Shouldn't y=c be y=b here? Otherwise I can't see the relation between the code and the shown plot.
      – eightx2
      May 1 '15 at 16:26










      up vote
      7
      down vote













      It seems that it's impossible to call csvreader inside draw plot coordinates { }. To avoid the plot command and still being able to plot lines between points, I need to use xdef to remember the previous point.



      begin{filecontents*}{data.csv}
      a,b,c,d
      1,4,5,1
      2,3,1,5
      3,5,6,1
      4,1,4,9
      5,3,4,7
      end{filecontents*}

      documentclass{article}
      usepackage[utf8]{inputenc}
      usepackage{csvsimple}
      usepackage{tikz}

      begin{document}
      begin{tikzpicture}
      csvreader[ head to column names,%
      late after head=xdefaold{a}xdefbold{b},%
      after line=xdefaold{a}xdefbold{b}]%
      {data.csv}{}{%
      draw (aold, bold) -- (a,b) node {$times$};
      }
      end{tikzpicture}
      end{document}


      I get the output below. Now I can get back to work and print a whole bunch of data in my report ;-) I love it !



      Plot of CSV data using <code>tikz</code> and <code>csvsimple</code>






      share|improve this answer



























        up vote
        7
        down vote













        It seems that it's impossible to call csvreader inside draw plot coordinates { }. To avoid the plot command and still being able to plot lines between points, I need to use xdef to remember the previous point.



        begin{filecontents*}{data.csv}
        a,b,c,d
        1,4,5,1
        2,3,1,5
        3,5,6,1
        4,1,4,9
        5,3,4,7
        end{filecontents*}

        documentclass{article}
        usepackage[utf8]{inputenc}
        usepackage{csvsimple}
        usepackage{tikz}

        begin{document}
        begin{tikzpicture}
        csvreader[ head to column names,%
        late after head=xdefaold{a}xdefbold{b},%
        after line=xdefaold{a}xdefbold{b}]%
        {data.csv}{}{%
        draw (aold, bold) -- (a,b) node {$times$};
        }
        end{tikzpicture}
        end{document}


        I get the output below. Now I can get back to work and print a whole bunch of data in my report ;-) I love it !



        Plot of CSV data using <code>tikz</code> and <code>csvsimple</code>






        share|improve this answer

























          up vote
          7
          down vote










          up vote
          7
          down vote









          It seems that it's impossible to call csvreader inside draw plot coordinates { }. To avoid the plot command and still being able to plot lines between points, I need to use xdef to remember the previous point.



          begin{filecontents*}{data.csv}
          a,b,c,d
          1,4,5,1
          2,3,1,5
          3,5,6,1
          4,1,4,9
          5,3,4,7
          end{filecontents*}

          documentclass{article}
          usepackage[utf8]{inputenc}
          usepackage{csvsimple}
          usepackage{tikz}

          begin{document}
          begin{tikzpicture}
          csvreader[ head to column names,%
          late after head=xdefaold{a}xdefbold{b},%
          after line=xdefaold{a}xdefbold{b}]%
          {data.csv}{}{%
          draw (aold, bold) -- (a,b) node {$times$};
          }
          end{tikzpicture}
          end{document}


          I get the output below. Now I can get back to work and print a whole bunch of data in my report ;-) I love it !



          Plot of CSV data using <code>tikz</code> and <code>csvsimple</code>






          share|improve this answer














          It seems that it's impossible to call csvreader inside draw plot coordinates { }. To avoid the plot command and still being able to plot lines between points, I need to use xdef to remember the previous point.



          begin{filecontents*}{data.csv}
          a,b,c,d
          1,4,5,1
          2,3,1,5
          3,5,6,1
          4,1,4,9
          5,3,4,7
          end{filecontents*}

          documentclass{article}
          usepackage[utf8]{inputenc}
          usepackage{csvsimple}
          usepackage{tikz}

          begin{document}
          begin{tikzpicture}
          csvreader[ head to column names,%
          late after head=xdefaold{a}xdefbold{b},%
          after line=xdefaold{a}xdefbold{b}]%
          {data.csv}{}{%
          draw (aold, bold) -- (a,b) node {$times$};
          }
          end{tikzpicture}
          end{document}


          I get the output below. Now I can get back to work and print a whole bunch of data in my report ;-) I love it !



          Plot of CSV data using <code>tikz</code> and <code>csvsimple</code>







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 23 '12 at 11:44

























          answered Nov 23 '12 at 11:28









          remjg

          1,2562923




          1,2562923






















              up vote
              2
              down vote













              Another example with csvsimple, tikz and pgf-pie.



              begin{filecontents*}{newData.csv}
              20,30,50
              end{filecontents*}

              documentclass[10pt,a4paper]{article}
              usepackage[utf8]{inputenc}

              usepackage{csvsimple}
              usepackage{tikz}
              usepackage{pgf-pie}

              begin{document}

              begin{tikzpicture}
              csvreader[no head]%
              {newData.csv}
              {1=colVali,2=colValii,3=colValiii}
              {%
              pie[polar, explode=0.1]
              {colVali/A, colValii/B, colValiii/C}
              }
              end{tikzpicture}

              end{document}


              Which produces the following pie chart:



              enter image description here






              share|improve this answer








              New contributor




              Mab is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.






















                up vote
                2
                down vote













                Another example with csvsimple, tikz and pgf-pie.



                begin{filecontents*}{newData.csv}
                20,30,50
                end{filecontents*}

                documentclass[10pt,a4paper]{article}
                usepackage[utf8]{inputenc}

                usepackage{csvsimple}
                usepackage{tikz}
                usepackage{pgf-pie}

                begin{document}

                begin{tikzpicture}
                csvreader[no head]%
                {newData.csv}
                {1=colVali,2=colValii,3=colValiii}
                {%
                pie[polar, explode=0.1]
                {colVali/A, colValii/B, colValiii/C}
                }
                end{tikzpicture}

                end{document}


                Which produces the following pie chart:



                enter image description here






                share|improve this answer








                New contributor




                Mab is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.




















                  up vote
                  2
                  down vote










                  up vote
                  2
                  down vote









                  Another example with csvsimple, tikz and pgf-pie.



                  begin{filecontents*}{newData.csv}
                  20,30,50
                  end{filecontents*}

                  documentclass[10pt,a4paper]{article}
                  usepackage[utf8]{inputenc}

                  usepackage{csvsimple}
                  usepackage{tikz}
                  usepackage{pgf-pie}

                  begin{document}

                  begin{tikzpicture}
                  csvreader[no head]%
                  {newData.csv}
                  {1=colVali,2=colValii,3=colValiii}
                  {%
                  pie[polar, explode=0.1]
                  {colVali/A, colValii/B, colValiii/C}
                  }
                  end{tikzpicture}

                  end{document}


                  Which produces the following pie chart:



                  enter image description here






                  share|improve this answer








                  New contributor




                  Mab is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  Another example with csvsimple, tikz and pgf-pie.



                  begin{filecontents*}{newData.csv}
                  20,30,50
                  end{filecontents*}

                  documentclass[10pt,a4paper]{article}
                  usepackage[utf8]{inputenc}

                  usepackage{csvsimple}
                  usepackage{tikz}
                  usepackage{pgf-pie}

                  begin{document}

                  begin{tikzpicture}
                  csvreader[no head]%
                  {newData.csv}
                  {1=colVali,2=colValii,3=colValiii}
                  {%
                  pie[polar, explode=0.1]
                  {colVali/A, colValii/B, colValiii/C}
                  }
                  end{tikzpicture}

                  end{document}


                  Which produces the following pie chart:



                  enter image description here







                  share|improve this answer








                  New contributor




                  Mab 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 answer



                  share|improve this answer






                  New contributor




                  Mab is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  answered Nov 20 at 20:52









                  Mab

                  213




                  213




                  New contributor




                  Mab is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.





                  New contributor





                  Mab is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.






                  Mab is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.






























                       

                      draft saved


                      draft discarded



















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f83888%2fhow-to-plot-data-from-a-csv-file-using-tikz-and-csvsimple%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 change which sound is reproduced for terminal bell?

                      Can I use Tabulator js library in my java Spring + Thymeleaf project?

                      Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents