Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

How to graph in Latex ?

  1. Nov 11, 2004 #1
    How do I plot graphs in LaTeX? Example sin(x) to begin with. :frown:

    Also, how do I insert pictures in LaTeX? Example, simple circuit diagrams.

    student :confused:
  2. jcsd
  3. Nov 11, 2004 #2


    User Avatar
    Gold Member

    You cannot actually graph in LaTeX. You can plot something for example in Mathematica, Matlab, or Gnuplot and export it to a JPEG or EPS file. Look up the \'figure' directive in the LaTeX documentation. 'figure' will allow you to include an EPS or JPEG file.
  4. Nov 21, 2004 #3
    What is the \figure syntax for including a .JPG file cause I personally haven' t been able to locate it for a while now.

  5. Nov 21, 2004 #4
    Any suggestions, guys, I really need to know how to import .jpg files urgently.

  6. Nov 21, 2004 #5
    I don´t know how to include .jpg, I only know how to include .eps. What I usually do when I have to include a figure is printing it to a file (PostScript printer), then convert it to .eps with Ghostview and then include the .eps-file. Not very elegant and a bit time-consuming but it works.
  7. Nov 21, 2004 #6
    you should use eps files because jpegs can't be scaled.
  8. Nov 21, 2004 #7
    ok but what' s the syntax for including a .eps file?

  9. Nov 21, 2004 #8
    \caption{Caption goes here}

    I checked to make sure that I put the pictures (.eps) into the same directory (C:) as the other latex files I have been compiling.....the caption appears but there is no picture. The other files (no picture) compile just fine.


    Help, James ! :cry:
    Last edited: Nov 21, 2004
  10. Jul 2, 2008 #9
    This is the correct LaTeX code for including a figure:

    Code (Text):
          \caption{\label{sin}The sine function.}
    This assumes that your sin(x) graph is in a file called "sin.eps" if you use plain "latex", or in a file called "sin.pdf" if you use "pdflatex".

    You could create such a graph by several tools including GNUPlot, GRI, Asymptote, R, Octave, Excel, and GLE. In GLE, you would create a script like this:

    Code (Text):
    size 12 10
    begin graph
       title "f(x) = sin(x)"
       xaxis min -2*pi max 2*pi dticks pi/2 format "pi"
       yaxis dticks 0.25 format "frac"
       let d1 = sin(x)
       d1 line color red
    end graph
    and save it as "sin.gle". Then you run the GLE program as follows: "gle -d pdf sin.gle" to create "sin.pdf" or "gle -d eps sin.gle" to create the "sin.eps".

    Finally, you run LaTeX on your ".tex" file to produce the final result. You can see an example of this using "pdflatex" here:

    Last edited: Jul 2, 2008
  11. Jul 11, 2008 #10
    Are you sure about the "\usepackage{graphics}"? Maybe there are couple of packages... In all my documents it "\usepackage{graphicx}".
    By the way, we can also specify which file exactly you want by entering the full name, like "sin.png" etc. If you have a priority of file types you want to use (lets say, png if available, otherwise eps, otherwise pdf), you can add after the "\usepackages"s part this line "\DeclareGraphicsExtensions{.png,.eps,.pdf}"
  12. Jul 11, 2008 #11


    User Avatar
    Homework Helper

    Both the graphicx and graphics packages are available. I have used both, but if I understand correctly, I believe graphicx can do more than the graphics package.

    You can use pstricks to include a plot of a sine curve (for example); it is "in LaTeX" in the sense that all you have to do is type in several lines in your TeX document. I have used it for function plots and data plots, among other things.

    However, if the issue is just to include a function plot in a document and you don't already know pstricks, I would agree with the advice in the above posts to use a separate plotting program (like gnuplot) to produce an eps figure, and then include the figure using the graphicx or graphics packages.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Similar Discussions: How to graph in Latex ?
  1. MacTeX vs LaTeX (Replies: 3)

  2. Latex in ereaders (Replies: 1)