# PGFPlots slow down compilation when plotting from external files

I am writing a report containing multiple plots of spectroscopic data by way of PGFplots which is fetching data from external files. It used to do the work, and after a few minutes of compilation it would render a pdf, but as I added more results to be plotted it slowed down and now it does not appear to ever finish. (I have waited for about an hour now)

The code I use is pretty much a repeat of this for thirteen different csv files, ranging between two columns and ten.

\documentclass{article}
\usepackage{graphicx,tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xlabel near ticks,axis background/.style={
fill=gray!70},width=\textwidth,height=0.4\textwidth,xticklabel=eV,
ymin=0,enlargelimits=false,ylabel=Counts,no marks,grid,cycle list name=color list]
\addplot table[x index=1,y index=2,col sep=space,row sep=crcr] {spectroscopy_data.csv};
\addlegendentry{C$_{\text{K}\alpha}$}
\addplot table[x index=1,y index=3,col sep=space,row sep=crcr] {spectroscopy_data.csv};
\addlegendentry{O$_{\text{K}\alpha}$}
\end{axis}
\end{tikzpicture}
\end{document}

-
does it compile if you comment out the first plots and only compile the last few? –  long tom Apr 9 '13 at 18:02
my typical experience is that it is extremely much faster (if you have many columns) to have every dataplot in a two column setup (yes, more files). This should give you some speedup. Or else you could read in the full data set (see the pgfplotstable manual for this) and this should yield a very nice speedup as well. –  zeroth Apr 9 '13 at 18:04
long tom: Yes. It does. I got it working by enabling tikz external as suggested by ExP. Even with the external library enabled running a first time compile on my ultrabook is a borderline hopeless task unless first compiled on my stationary i7. Thankfully the problem is solved now! zeroth: That does seem to help! Thank you very much :) –  Mr. V Apr 11 '13 at 6:45

For plots of large data-files, I recommend the TikZ-library external. It allows to compile your plots separately from your main document. This way, your main document will be typeset within seconds, while you can compile the plots one by one (if desired even in parallel).