PDA

View Full Version : How to graph in Latex ?


student1938
Nov11-04, 05:49 AM
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:

graphic7
Nov11-04, 08:06 AM
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.

JamesJames
Nov21-04, 12:18 PM
What is the \figure syntax for including a .JPG file cause I personally haven' t been able to locate it for a while now.

James

JamesJames
Nov21-04, 04:20 PM
Any suggestions, guys, I really need to know how to import .jpg files urgently.

James

Atheist
Nov21-04, 05:31 PM
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.

nbo10
Nov21-04, 06:04 PM
you should use eps files because jpegs can't be scaled.

JamesJames
Nov21-04, 09:29 PM
ok but what' s the syntax for including a .eps file?

James

JamesJames
Nov21-04, 10:16 PM
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{figure}
\centering
\includegraphics{filename.eps}
\caption{Caption goes here}
\end{figure}
end{document}

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.

IT SAYS LATEX ERROR: UNKNOWN GRAPHICS EXTENSION : EPS!

Help, James ! :cry:

Jeans
Jul2-08, 12:55 AM
This is the correct LaTeX code for including a figure:

\documentclass{article}
\usepackage{graphics}
\begin{document}
\begin{figure}
\includegraphics{sin}
\caption{\label{sin}The sine function.}
\end{figure}
\end{document}

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:


size 12 10
begin graph
math
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:

http://www.gle-graphics.org/latex/graph.pdf

The-herod
Jul11-08, 07:17 AM
This is the correct LaTeX code for including a figure:

\documentclass{article}
\usepackage{graphics}
\begin{document}
\begin{figure}
\includegraphics{sin}
\caption{\label{sin}The sine function.}
\end{figure}
\end{document}


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}"

alphysicist
Jul11-08, 10:07 AM
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}"

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.

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:

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.