# Gnuplot and Latex

1. Jul 30, 2007

### NeoDevin

I'm generating a graph in gnuplot, using the postscript enhanced terminal setting, and trying to use symbols in the axes labels, then import the ps file into a latex document. The trouble I'm having is that the symbols in the ps document, don't show up properly in the final document after the latex source is compiled. I have tried using term pslatex, but when I use it, it compiles, but then the previewer gives me an error when it tries to show. I tried using term latex, but then the latex compiler complains that there is no bounding box.

Any ideas anyone?

2. Jul 30, 2007

### mgb_phys

Not used gnuplot + latex recently but generally tex needs encapsulated postscrpt, this is the cause of the bounding box error.
I don't know if gnuplot can generate eps but ghostview can certainly convert ps->eps.

3. Jul 30, 2007

### D H

Staff Emeritus
The pstricks output from gnuplot coupled with the pstricks LaTeX package make very beautiful, colored graphs. IMHO, the postscript output is not nearly as nice looking. The pstricks output is native LaTeX. No goofy postscript needed. It works with both the basic latex processor, producing .dvi and .ps files and with pdflatex, which produces .pdf files directly.

As an aside, I much prefer the latter. PDF files generated from postscript files have this ghostly view to them (pun intended). PDF files generated directly via pdflatex take advantage of the PDF bookmark capabilities.

So how to use pstricks? In gnuplot, simply set term pstricks. In your latex document (I am assuming pdflatex here), I use
Code (Text):

\usepackage{graphicx}
\usepackage{ps4pdf}
\PSforPDF{
\usepackage{pstricks}
}

4. Jul 31, 2007

### malawi_glenn

I almost always do "print screen" to convert the picture from gnuplot to paint or similar and save it as a .png file. I think png-files look up nicer in Latex :P

5. Jul 31, 2007

### NeoDevin

What file extension should I use for pstricks? it tells me that .ps unrecognized when I try to pdflatex it.

Last edited: Jul 31, 2007
6. Jul 31, 2007

### D H

Staff Emeritus
First things first: Look at the gnuplot/pstricks output file. It's native LaTeX! You simply input them.

I should have looked deeper into a file where I used the packages. All I showed above is the preamble. You have also have to embed each input{pstricks_file} in a PSforPDF macro:
Code (Text):

\begin{figure}
\centering
\PSforPDF{
\input{foobarplot}
}
\caption{Foo as a function of bar}
\label{fig:foobar}
\end{figure}

Some useful websites are CTAN, the Comprehensive TeX Archive Network, at www.ctan.org and TUG, the TeX Users Group, at www.tug.org. The former hosts the searchable TeX catalogue online. Some relevant pages:
Note that the ps4pdf catalog entry notes that ps4pdf is deprecated and that you should use the pst-pdf or pdftricks package instead. I suggest you look into these as alternatives. However, ps4pdf works quite nicely for me and I don't have to touch the gnuplot output to use it.

7. Jul 31, 2007

### NeoDevin

Thanks muchly, I will look into those packages and see what I find, I was trying to include it with \includegraphics commands. Silly me.

8. Mar 5, 2009

### Anglea

please can anyone help me to plot with colors in G N U P L O T
Version 4.0 patchlevel 0, as I found some commands somewhere online, but it does not work, can you plaes show me how to do it, and how to add legends.....

9. Mar 5, 2009

### NeoDevin

try:
Code (Text):
set te post enhanced color
should make your output postscript with colour.

10. Mar 6, 2009

### Anglea

Really appreciate your time, any further help would be much appreciated actually I have already such a command, what I meant is to set certain colors by these commands s
PHP:
et style line 1 lt 1 lw 6
set style line 2 lt 3 lw 8 pt 7 ps 2
which allows to choose certain color, but is not working with me, also do you any ides how to add a small box which magnify a small part of the figure usually appear in the right top side on the figure

11. Apr 8, 2009

### Anglea

ANYONE plaes show me how to add the time in Latex presentation and slide number??

12. Aug 28, 2009

### Anglea

Please could anyone give me a hand in this.......I've been struggling for a while of using GNUPLOT
to plot a file of 3 columns as a contour plot, but it gave me warning
message say {can not contour non grid data}, even I used the command
Code (Text):

set dgrid3d 10,10, 16
set dummy u,v
set parametric
dummy variable is t for curves, u/v for surfaces
set contour base
set style data lines
splot 'myfile'

cheers

13. Sep 2, 2009

### axluca

How can I insert LateX mathematics symbols in a plot with Gnuplot?

I know how to do it using
Code (Text):
set terminal latex
and sending the output on a latex file from gnuplot, but I would like to include symbols directly in a gnuplot file *.plt so that they are shown when I draw the output with gnuplot.

14. Oct 6, 2009

### Anglea

Hi
have alook at this link, it explains how to add symbols like Greek letters

http://t16web.lanl.gov/Kawano/gnuplot/label-e.html [Broken]

Last edited by a moderator: May 4, 2017
15. Jul 16, 2010

### axluca

Do you know how to print in color directly from gnuplot? When I print it only displays BW.

16. Sep 2, 2010

### mersecske

It is possible to use:

plot for [i=1:10] ......

in parametric plot???