# Quality loss at adding images to a LaTeX file

I have a LaTeX file (compiled with pdflatex) with some images in pdf added via the \includegraphics command. The problem is that the images are really big (up to 10MB) and the output file is too large (more than 30MB).

The images have been obtained via the splot command in gnuplot but there are a lot of points in the splot.

I have tried to get the images in other formats (.jpg, .png basically) since the file size is considerably lower and thus the size of my resulting .pdf is also lower. But when I include this files in my LaTeX document the images lose a lot of quality (even though they have OK quality when viewed separately).

How could I get a small pdf file from pdflatex without sacrificing too much quality on the images? I suppose that the problem lies in resizing the image from the pdf-latex but can't solve it. Or in other words, how can I obtain smaller .pdf images (or other format accepted by pdflatex) without losing too much quality when added to the pdf file?

The LaTeX command is \includegraphics[width=7cm]{file.pdf}. Note that I have to resize them to fit 7cm width.

EDIT:

I add 4 files (original images in .pdf, .png and .jpeg and resulting pdf file compiled with pdflatex. Here's the latex code too.

List of files

\documentclass[a4paper,10pt]{article}
\usepackage[utf8x]{inputenc}
\usepackage[pdftex]{graphicx}

\begin{document}

\begin{figure}
\centering
\includegraphics[width=7cm]{numeric.pdf}
\caption{Pdf file.}
\end{figure}

\begin{figure}
\centering
\includegraphics[width=7cm]{numeric.png}
\caption{Png file.}
\end{figure}

\begin{figure}
\centering
\includegraphics[width=7cm]{numeric.jpeg}
\caption{Jpeg file.}
\end{figure}

\end{document}

-
Welcome to TeX.SX! You may have a look on our starter guide. – Corentin May 20 '13 at 16:59
If you make a png with the exact size as you need it, the quality will be perfectly fine. Just when you start scaling the issues begin – Martin H May 20 '13 at 17:18
When you include raster graphics using pdflatex, even when scaling, there is no loss of information. pdflatex doesn't alter the image in any way. What you're describing is most likely an issue with your PDF viewer. If you print the document, you should find that the quality is the same as in the original image file. – Jake May 20 '13 at 17:35
@dustin: Well, if the quality of your source image is too low for the intended use (viewing on screen or printing), of course pdflatex can't do anything about it, but including the image using pdflatex will not degrade the quality in any way. – Jake May 20 '13 at 17:42
Depending on how you're going to print it, I would go with 1200dpi for a laser printer, or 600dpi if it's an inkjet printer. So if you need your final image to be 8cm by 4cm, that would be 3840 by 1920 pixels, which you could set using set terminal pngcairo size 4000,2500 font ",90" lw 10 (note that there is no option to specify the resolution directly, unfortunately, so you'll need to take care of scaling the line widths and font size manually). – Jake May 20 '13 at 18:56

I get really good quality saving my files as eps with a dpi setting of 1000 in Python. With this setting, I can zoom in at the highest level and there is no loss of quality with the lines.

I don't know if there is a way for you to set the dpi in gnuplot. If you can't, make the plot in Python or do it in tikz/pgf-plots.

If you want to check the quality, check out this post I have on code review and run the code.

python optimize ode solving

Edit:

Here is a link to download the files they look better then the google doc output (this isn't the same image the code link produces just the first two I could find the fastest).

converted to pdf

eps

Edit 2:

Here is your data in a pdf compiled in latex(an image of it at least). I deleted the first line that said x, t, u from the datagrid file.

Code: Open ipython with the alias ipython --pylab=qt

from mpl_toolkits.mplot3d import axes3d
import numpy as np
import pylab

unpack = True)
x = x.reshape(-1, 701)
t = t.reshape(-1, 701)
u = u.reshape(-1, 701)

fig = pylab.figure()
ax = fig.add_subplot(111, projection = '3d')
cmap = pylab.get_cmap('selection')
ax.plot_surface(x, t, u, cmap = cmap, linewidth = 0)
pylab.savefig('name.eps', format = 'eps')
pylab.show()


Here are selection options I like: Accent, gist_rainbow, jet, and Paired.

To save it in a rotate form, you need: ax.view_init(elev=elevation_angle, azim=azimuthal_angle) and add in the angle changes which the plot will show you on the bottom as you rotate it.

Edit 3:

From my understanding of reading the gnuplot manual on set hidden3d, set hidden3d hides portion of the plot that wouldn't be viewable from certain angles since in real life we can't see through the object. This by default how the plot is viewed in python. You can't see everything and will obtain different views by rotating the plot. Therefore, I don't think there is anything that needs to be set to accomplish this goal.

-
How big are your files? My problem is that eps/pdf files are too big (>10MB). And with other formats, after addding them to the latex file they lose a lot of quality. – gunbl4d3 May 20 '13 at 17:29
yes, your quality is high enough, but it does not solve my problem. I believe my problem lies when I add the files to the latex file (appart from huge eps/pdf files). – gunbl4d3 May 20 '13 at 18:28
they are 3d-plots made using a grid for a specific differential equation. I don't think it will improve the size unless I decrease the spacing of the grid, which I cannot do due to some pecualiarities of the equation. – gunbl4d3 May 20 '13 at 19:52
I have to plot the following file I produced using a C program: file – gunbl4d3 May 20 '13 at 20:02
@gunbl4d3 dustin: is it possible to absorb all relevant comments inside Q & A respectively to become a crispy standalone knowledge entity for future visitors and clean comments which are not required. could you provide a gnuplot splot code to try with gnuplottex and have a look at some approaches. – texenthusiast May 21 '13 at 1:24