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

Quality graph with gnuplot and latex

  1. Dec 3, 2011 #1
    I want to include graphics in a latex document, so I used various terminal (png, jpg) in gnuplot but when I include in latex, the result it isn't very good...i would coloured graph , so which terminal i can use? what pagkage i have to include in tex file?

    Thanks for helpers
     
  2. jcsd
  3. Dec 3, 2011 #2

    Simon Bridge

    User Avatar
    Science Advisor
    Homework Helper
    Gold Member
    2016 Award

    Pure LaTeX prefers postscript or encapsulated postscript (ps or eps) files.
    These can get very big, especially for color.

    PdfLaTeX will handle many different compressed file formats, which will look bad if you scale them in your document - especially graphs, like those produced by gnu plot, which usually have thin lines. The answer is to create the images at the size you want to use it - maybe rescaling it with an image manipulaton program (I use GIMP for eg.) For graphs or diagrams which have lots of lines and thin bits that are important, you want a format that uses lossless compression like png.
     
    Last edited: Dec 3, 2011
  4. Dec 3, 2011 #3

    robphy

    User Avatar
    Science Advisor
    Homework Helper
    Gold Member

    What is the nature of the graphics?
    If the graphics are fine lines and dots, then use vector-formats (like .eps) since they look better when rescaled. Otherwise, use raster-formats (like .png).

    Have you seen
    http://t16web.lanl.gov/Kawano/gnuplot/postscript-e.html [Broken]


    In latex, use the graphics or graphicx packages.
    http://t16web.lanl.gov/Kawano/gnuplot/postproc-e.html [Broken]
     
    Last edited by a moderator: May 5, 2017
  5. Dec 3, 2011 #4
    in the graphs are fine lines and dots...I try to set terminal gnuplot:
    Code (Text):

    set terminal epslatex size 4,2.82 standalone color colortext 9
    set output 'image.tex'
    plot f(x) # example
    but i want to insert graph in a tex file, to be converted in a pdf file. so:

    Code (Text):
    latex image.tex
    dvips image.dvi
    ps2pdf image.ps
    and then in tex file:
    Code (Text):

    \includegraphics[scale=1.00]{image.pdf}
    .

    The result is fine, but there is a better solution?
     
    Last edited by a moderator: May 5, 2017
  6. Dec 3, 2011 #5

    robphy

    User Avatar
    Science Advisor
    Homework Helper
    Gold Member

    Maybe something like this....

    set terminal postscript size 4,2.82 standalone color colortext 9
    set output 'image.eps'
    plot f(x) # example

    and then in the latex file:

    \includegraphics[scale=1.00]{image.eps}
     
  7. Dec 3, 2011 #6
    generating pdf file the graph doesn't appear: i use gedit-latex plugin so i export in pdf pressing ctr+alt+1...
     
  8. Dec 3, 2011 #7

    Simon Bridge

    User Avatar
    Science Advisor
    Homework Helper
    Gold Member
    2016 Award

    I've been using:

    \usepackage[pdftex]{color,graphicx}

    In the body:

    Code (Text):
    \begin{figure}
    \centering
    \includegraphics[angle=0, width=0.67\textwidth]{my-pic.png}
    \end{figure}
    [actually reads what I've been told]
    Oh yeah - it is supposed to do pdf - I'll go try to repeat your problem.
    [edit]
    Hmmm ... works for me using:

    ps2pdf testimage.eps

    ... and using the same

    \includegraphics[scale=1]{testimage.pdf}

    ... you did.

    Suggest:
    1. check the image is not blank at each stage in the processing
    2. use pdflatex directly in the terminal
    3. try just using the ps

    Sounds to me like your shortcut is only invoking latex, not pdflatex.
     
    Last edited: Dec 3, 2011
  9. Dec 3, 2011 #8
    this is the preamble:

    Code (Text):
    \documentclass[a4paper,italian,12pt]{article}
    \usepackage{babel}
    \usepackage[hmargin=2.5cm,vmargin=2.5cm,dvips]{geometry}
    %%\usepackage{draftcopy}
    \usepackage[latin1]{inputenc}
    \usepackage{ae}
    \usepackage{aecompl}
    \usepackage{aeguill}
    \usepackage{textcomp}
    \usepackage{mathcomp}
    %% \usepackage[draft]{graphicx}
    \usepackage[final]{graphicx}
    \usepackage{latexsym}
    \usepackage{amstext}
    %% \usepackage[mathlines,pagewise]{lineno}
    \usepackage{xspace}
    \usepackage[section,below]{placeins}
    \usepackage{array}
    \usepackage{tabularx}
    \usepackage{subfigure}
    \usepackage[small]{caption}
    \usepackage{url}
    \usepackage{booktabs}
    \usepackage{afterpage}
    \usepackage{parskip}
     
    ...
    \begin{center}
            \includegraphics[scale=1.60]{img/image.eps}
        \label{fig:image}
    \end{center}
     
    when i use pdflatex:

    Code (Text):
    ! LaTeX Error: Unknown graphics extension: .eps.
     
  10. Dec 3, 2011 #9

    Simon Bridge

    User Avatar
    Science Advisor
    Homework Helper
    Gold Member
    2016 Award

    pdflatex does not recognize eps.

    It should recognize .pdf though.
    Use regular LaTeX for eps files.
    (when testing, change only one thing at a time.)

    I'm getting a blank page instead of an image - this what you get?
    The error is:

    LaTeX Warning: Float too large for page [...]

    When I convert to pdf, the image is A4 size with the image in the bottom-left corner - which is off the bottom of the page!

    epstopdf image.eps

    creates a properly dimentioned file.

    I tried this with your code, (Oh cool - Italian!) and all your includes (jic there were conflicting packages) and it worked for me.
    Curiously, when I use just plain latex I get an error:

    ! LaTeX Error: Cannot determine size of graphic in image.pdf (no BoundingBox).

    But it works anyway ... so I guess I was wrong about latex graphicx not accepting pdf format.
     
    Last edited: Dec 3, 2011
  11. Dec 3, 2011 #10
    yes, converting eps or ps to a pdf it works... but in this way the quality of lines became a bit low :(
     
  12. Dec 3, 2011 #11

    Simon Bridge

    User Avatar
    Science Advisor
    Homework Helper
    Gold Member
    2016 Award

    Though you are scaling up - so you must get pixelation.
    You don't seem to be invoking any of the special features of pdf files, you you could load the eps file in the .tex then use normal latex to get a .dvi file, then dvipdf.

    Even so - recall that pdf uses (lossy) jpeg compression.
    If you just need to print it - use dvips instead and print the (likely huge) ps document.
    If you need to submit electronically, maybe they will accept a ps document compressed with zip?

    You can use a plotting program other than gnu-plot - pl-plot for eg also has octave bindings (which is how I use gnu-plot).

    However: I just run gnu-plot outputs through GIMP > filter > enhance > anti-alias.
    Also good for labeling them in a nice font, and resizing (smart enlarge or use the standard interpolation). If you have lots, then you'll want script-fu or just write a shell-script for image-magick.
     
  13. Dec 3, 2011 #12

    jhae2.718

    User Avatar
    Gold Member

    You could also try converting the image from .eps to .png with ImageMagick (sudo apt-get install imagemagick should work for Debian-based distros). In a terminal:
    Code (Text):

    convert -density 300 image.eps image.pdf
     
    I use a script that calls this to convert MATLAB generated .eps files to PNG for pdf[itex]\LaTeX[/itex].

    Increasing the image density should increase quality at the expense of a larger image size.
     
  14. Dec 3, 2011 #13

    robphy

    User Avatar
    Science Advisor
    Homework Helper
    Gold Member

    I don't use pdflatex, partly because of the lack of .eps support, and partly because i am comfortable with the latex -> dvips -> ps2pdf script that I use.

    I'd prefer keep the [original] vector-graphics, rather than converting it to a raster format, then including that alternate file.
     
  15. Dec 3, 2011 #14

    AlephZero

    User Avatar
    Science Advisor
    Homework Helper

    You need to indetsand the difference between bitmap graphics and vector graphics here.

    If you want to preserve "high quality" graphics when you to scale them to any size, you need vector graphics which defines each line by the "exact" coordinates of its end points, not bitmap graphics which defines a rectangular grid of pixels. When you scale bitmap graphics, the pixels just get bigger. When you scale vector graphics, the software "re-draws" the lines at the new scale to make the best use of the screen or printer resolution.

    PS, EPS, and PDF files can contain either bitmap or vector graphics, so you need to make sure that when you convert PS or EPS to a PDF you don't "accidentally" convert vector graphics into a bitmap.

    Somebody said "PDF uses lossy compression". Again that is only partly true - PDF can use either lossy or lossless compression, or no compresssion at all.

    The bottom line is that the EPSTOPDF program that comes with most versions of TeX does the conversion right. If the EPS file is vector graphics from GNUPLOT, the PDF will contain the exact same vector graphics. Other file conversion programs might do it wrong, or have the options that let you choose whether to do it right or wrong (but why bother, since EPSTOPDF doesn't have any options, and does it right).

    PNG is a bitmap graphics format with lossless compression. so it will work fine providing you don't want to scale the images. Otherwise, unless you have very complex plots from GNUPLOT, there's unlikely to be any advantage in terms of file size in using PNG rather than EPS and PDF.
     
  16. Dec 3, 2011 #15

    Simon Bridge

    User Avatar
    Science Advisor
    Homework Helper
    Gold Member
    2016 Award

    Well fair enough - in post #4, it was a bit unclear what you were doing to what.
    It started out looking like you converted some image to pdf for inclusion into your document.

    ... which suggested you were using pdflatex directly via this plugin.

    Define "better"? How would you decide?

    The sort answer is "yes - but..."

    When other suggestions for post-processing were suggested, you respond:
    Well then you prefer the lower quality.

    You could try plplot instead, or use the scilab plotting library. Or shell out for a commercial math-script engine like mathematica or matlab.
     
  17. Dec 3, 2011 #16

    Simon Bridge

    User Avatar
    Science Advisor
    Homework Helper
    Gold Member
    2016 Award

    dvipdf is the conversion utility used - iirc it does not support FlateEncode?

    I suppose he should also use dvipdfm instead of dvipdf, supports flate, his text would look better too. Not found how to flag this on CLI, though the -z option sets the compression ratio. afaik the default is still DCTEncode

    Instead you have to open up your .eps file in a text editor and insert the following after the end of the "%" commented area at the beginning of the file:
    Code (Text):
    systemdict /setdistillerparams known {
    << /AutoFilterColorImages false /ColorImageFilter /FlateEncode >> setdistillerparams
    } if
    Another option may be to use tex4ht, then open the .odt file in OpenOffice.org or Libre Office, and use the distiller there to create the PDF.
    Those programs have a GUI to select the PDF options and it defaults to lossless. Doesn't convert all that nicely into OO fonts though, probably have to fiddle with the cli options. One can also export directly from Lyx, never tried.

    Rasterizing images is the recommended "best practice" where file-size is important.

    -------------------------------------
    references:
    http://electron.mit.edu/~gsteele/pdf/
    http://gaspra.kettering.edu/dvipdfm/dvipdfm-0.12.4.pdf [Broken]
     
    Last edited by a moderator: May 5, 2017
  18. Dec 4, 2011 #17
    i don't say this:
    "I'd prefer keep the [original] vector-graphics, rather than converting it to a raster format, then including that alternate file."

    i'm dirac68! :devil:
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Quality graph with gnuplot and latex
  1. Gnuplot and Latex (Replies: 15)

  2. Graphs in LaTeX (Replies: 3)

Loading...