Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
4  
Can you provide some detail as to exactly what you are looking for. You can use pgfplots to draw graphs. –  Peter Grill Jul 6 '12 at 5:00
4  
The pgfplots documentation shows how this can be done. There's also the pstricks 2D plot and 3D plot gallery. –  Werner Jul 6 '12 at 5:31
2  

2 Answers 2

Well pgfplots definitely:

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\begin{document}

\begin{tikzpicture}
    \begin{axis}[domain=-2*pi:2*pi]
    \addplot[mark=none, samples=100, red] function {sin(x)};
    \end{axis}
\end{tikzpicture}

\end{document}

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

share|improve this answer

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.

share|improve this answer
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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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