Quality graph with gnuplot and latex

In summary, the conversation discusses the use of graphics in a latex document, with a focus on using various terminal formats in gnuplot and including them in a tex file. It is suggested to use postscript or encapsulated postscript (ps or eps) files for pure LaTeX, and pdfLaTeX can handle different compressed file formats. To ensure the best quality for graphs and diagrams with thin lines, a format with lossless compression such as png is recommended. The conversation also covers issues with scaling and converting eps files to pdf, and suggests using image manipulation programs or other plotting programs for better results.
  • #1
dirac68
10
0
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
 
Physics news on Phys.org
  • #2
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:
  • #3
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:
  • #4
robphy said:
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]

in the graphs are fine lines and dots...I try to set terminal gnuplot:
Code:
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:
latex image.tex 
dvips image.dvi
ps2pdf image.ps

and then in tex file:
Code:
\includegraphics[scale=1.00]{image.pdf}
.

The result is fine, but there is a better solution?
 
Last edited by a moderator:
  • #5
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}
 
  • #6
robphy said:
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}

generating pdf file the graph doesn't appear: i use gedit-latex plugin so i export in pdf pressing ctr+alt+1...
 
  • #7
I've been using:

\usepackage[pdftex]{color,graphicx}

In the body:

Code:
\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:
  • #8
this is the preamble:

Code:
\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:
! LaTeX Error: Unknown graphics extension: .eps.
 
  • #9
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:
  • #10
yes, converting eps or ps to a pdf it works... but in this way the quality of lines became a bit low :(
 
  • #11
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.
 
  • #12
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:
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.
 
  • #13
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.
 
  • #14
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.
 
  • #15
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.

gedit-latex plugin so i export in pdf pressing ctr+alt+1
... which suggested you were using pdflatex directly via this plugin.

The result is fine, but there is a better solution?
Define "better"? How would you decide?

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

When other suggestions for post-processing were suggested, you respond:
I'd prefer keep the [original] vector-graphics, rather than converting it to a raster format, then including that alternate file.
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.
 
  • #16
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:
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:
  • #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:
 

1. What is gnuplot and how does it help create quality graphs?

Gnuplot is a command-line program that allows users to create high-quality graphs and plots from data. It can handle various types of data and produce customizable 2D and 3D plots with a wide range of formatting options, making it a powerful tool for visualizing data. The output can be saved in various formats, including LaTeX, making it easy to incorporate into documents for publications or presentations.

2. How does gnuplot integrate with LaTeX?

Gnuplot can output graphs in LaTeX format, which can then be included in LaTeX documents using the \includegraphics command. This allows for seamless integration of high-quality graphs into documents, with the added benefit of being able to use LaTeX's mathematical typesetting for labels and annotations on the graph.

3. Can gnuplot handle large datasets?

Yes, gnuplot is designed to handle large datasets efficiently. It can plot millions of data points without compromising on the quality of the graph. It also has features such as data smoothing and data filtering, which can help simplify complex data and make it easier to visualize.

4. Is gnuplot suitable for scientific data analysis?

Yes, gnuplot is widely used in the scientific community for data visualization and analysis. It has a wide range of features and options that make it suitable for analyzing and presenting various types of data. It is also highly customizable, allowing scientists to create graphs and plots that meet their specific research needs.

5. Is gnuplot difficult to use for beginners?

Gnuplot can be intimidating for beginners due to its command-line interface and extensive range of options. However, there are numerous resources available online, including tutorials and user guides, that can help beginners get started. Once the basics are understood, gnuplot can be a powerful and versatile tool for creating quality graphs.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
23
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
11
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
6K
Back
Top