[Tex/LaTex] Problem with a very heavy EPS image – scatter plot too heavy as EPS

conversionepsgraphics

Using Stata, I produced a scatter plot of some variables. I saved the image as an EPS file. There are around a 1000 dots in the scatter plot – and this makes the EPS file to be 26MB. I need to use this image in my LaTeX file (I use TeXnicCenter and compile as LaTeX => PS => PDF). The problem is that it produces a PDF file that takes a long time to load the page displaying the image. I don't need this image to be super sharp – there is no real point in zooming it in too much. Furthermore, the PDF I get is quite heavy for a 16 pages document. Is there anything I could do to improve the loading time of the page with the drawing, and decreasing the size of the PDF file? For example,

  1. Would it be an improvement if I convert the image to JPEG, PNG, or BMP? Would it decrease the image size?

  2. Is there a way to tell LaTeX to keep using the EPS image, but decrease the quality of the image?

Best Answer

As noted in the comments on the question, EPS is not an ideal way to store the plot. For scatter plots with many points and also for pseudo colour plots, it's a better idea to store the plot itself (without axes and annotations) as a raster graphic such as a PNG. In the case of a pseudo colour plot, this is actually minimal and no information is lost. See this answer for an example I did of one.

As a sample, I plotted random points in octave and then turned off the axes. After saving as a PNG file, I used imagemagick to trim the margins from the plot to produce scatter.png:

enter image description here

Using pgfplots I wrapped this PNG in axes, thus minimising the the space and processing required by the points in the plot. This requires the use of pdflatex rather than latex with a PNG file.

enter image description here

\documentclass[10pt]{article}
\usepackage{pgfplots}
\pgfplotsset{width=6cm,compat=newest}

\begin{document}

\begin{figure}[ht]
\centering
\begin{tikzpicture}
    \begin{axis} [
        scale only axis,        % Plot size does not include axes.
        enlargelimits=false,    % Shrink wrap the PNG.
        axis on top,            % Axes placed over PNG to avoid obscuring the lines.
        xlabel=$x$,
        ylabel=$y$,
    ]
        \addplot graphics [
            xmin=0,
            xmax=1,
            ymin=0,
            ymax=1,
        ] {scatter.png};
    \end{axis}
\end{tikzpicture}
\caption{A simple example.}
\end{figure}

\end{document}