[Tex/LaTex] How to use very large data sets with pgfplots w/o making pdf take a very long time to load


I'm working with a very large data set – almost 120,000 observations – and I'm using pgfplots to make some plots. The process goes ok, especially with the use of the external library, but the pdf documents take a very long time to load. It seems as though adobe is individually drawing each data point.

Is there a better way to use pgfplots to make the plots easier to render?

My set up is:



\caption{Publicly Available Num Tested, MEAP\_stacked Number Valid}
only marks,
ylabel={Number Tested, Public Data},
xlabel={Number Valid, Our Data},
area legend,
legend style = {at={(axis cs:700,0)},anchor=south east},
\addlegendentry{Social Studies}


I'm using pdfLaTeX and Ubuntu with TeXLive.


Best Answer

This answer may need pgf CVS, I do not know.

The external lib can be customized to produce png on its own -- with correctly scaled images.

The pgfmanual for pgf (CVS?) describes the process in all detail in Section 34.7 Bitmap Graphics Export in its documentation of the external library.

The trick is to use

    % Defines a custom style which generates BOTH, .pdf and .png export
    % but prefers the .png on inclusion.
    % This style is not pre-defined, you may need to copy-paste and
    % adjust it.
    png export/.style={
        external/system call/.add={}{; convert -density 300 -transparent white "\image.pdf" "\image.png"},
        /pgf/images/external info,
        /pgf/images/include external/.code={%
    png export,% ACTIVATE

in your preamble.

There are three steps involved:

a) modification of the system call (no problem, should be possible with any version of the external lib)

b) the /pgf/images/external info key (which is probably pgf CVS, only) which generates TeX dimension information for every exported image and stores it appropriately.

c) the use of \pgfexternalwidth when loading the image (this is actually output of this 'external info' thing).

The \tikzset statement in my suggested solution defines a new style 'png export'. Rather than activating it globally as in my solution, you may just enable it for a single picture by

{% from here on, png export will be used....
\tikzset{png export}%
}% here ends the png export