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

Gnuplot and Latex

  1. Jul 30, 2007 #1
    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. jcsd
  3. Jul 30, 2007 #2


    User Avatar
    Science Advisor
    Homework Helper

    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.
  4. Jul 30, 2007 #3

    D H

    User Avatar
    Staff Emeritus
    Science Advisor

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

  5. Jul 31, 2007 #4


    User Avatar
    Science Advisor
    Homework Helper

    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
  6. Jul 31, 2007 #5
    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
  7. Jul 31, 2007 #6

    D H

    User Avatar
    Staff Emeritus
    Science Advisor

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

      \caption{Foo as a function of bar}
    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.
  8. Jul 31, 2007 #7
    Thanks muchly, I will look into those packages and see what I find, I was trying to include it with \includegraphics commands. Silly me.
  9. Mar 5, 2009 #8
    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.....
  10. Mar 5, 2009 #9
    Code (Text):
    set te post enhanced color
    should make your output postscript with colour.
  11. Mar 6, 2009 #10
    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
    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
  12. Apr 8, 2009 #11
    ANYONE plaes show me how to add the time in Latex presentation and slide number??
  13. Aug 28, 2009 #12
    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'
  14. Sep 2, 2009 #13
    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.
  15. Oct 6, 2009 #14
    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
  16. Jul 16, 2010 #15
    Do you know how to print in color directly from gnuplot? When I print it only displays BW.
  17. Sep 2, 2010 #16
    It is possible to use:

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

    in parametric plot???
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook