I am in need of displaying line graphs in a LaTeX document but I can't figure out how. I searched on Google but did not receive any promising results. Is it really possible to do this within LaTeX or will I have to embed a jpeg image of a line graph created in Excel?


Well pgfplots definitely:


    \addplot[mark=none, samples=100, red] function {sin(x)};


enter image description here

Its simple, clean and will produce high quality plots, which fit perfectly into the document style. For more complex plots you may use gnuplot for computation. pgfplots can include table files as well (data stored in columns such tables gnuplot prints).


I suggest you better create your plots by another application similar e.g. Octave in order to create graphs like: Plot

See e.g. here for further reference. In my opinion LaTeX is only suitable to create very basic graphs that are not likely to be changed often. Otherwise I'd always recommand to use plotting tools and export the graphics as vector images and include them to your LaTeX file.

  • 3
    I would absolutely disagree with this and recommend that one use other tools if you have only one or two basic graphs to do. If you have a lot of them, and are not straightforward you should use pgfplots. It is quite an awesome package. – Peter Grill Jul 6 '12 at 6:43
  • 2
    I agree with Peter's comment. I used to create all my plots using external programs and then included them in the LaTeX file afterwards, but after switching to pgfplots, I find that approach vastly less comfortable and much harder to maintain. Also, it's near impossible to create plots that really match the document style using external tools. I'd like to see an example for a plot that couldn't be created directly within LaTeX. – Jake Jul 6 '12 at 6:57
  • 2
    In addition to Peter's and Jake's comment, I would like to say something on a different aspect. For my thesis I have to perform a lot of simulations and pgfplots is really saving my time in creating reports; I can make a graphic almost in real time simply starting from .dat file. That's besides the quality aspect.. for these two reasons pgfplots is the right tool to make graphs in LaTeX IMHO. – Claudio Fiandrino Jul 6 '12 at 8:21
  • 2
    @Peter and @Jake: actually after doing some research as far as the pgfplots package is concerned, I'm reconsidering my answer (and even my normal approach to this). The package appears to be very useful and I'm trying to create my next visualisations with it - and perhaps I'm switching for good... Thank you for the hint! – Eric Jul 6 '12 at 8:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.