\documentclass{article}

\usepackage{pgfplots}
%\pgfplotsset{compat=1.8}
\usepgfplotslibrary{external}
%\tikzset{external/system call={lualatex \tikzexternalcheckshellescape -halt-on-error -interaction=batchmode -jobname "\image" "\texsource"},external/shell escape=-shell-escape}
%\tikzset{external/system call={pdflatex \tikzexternalcheckshellescape -halt-on-error -interaction=batchmode -jobname "\image" "\texsource"},external/shell escape=-shell-escape}
%%externalize the plots 
\tikzexternalize

\begin{document}

\begin{tikzpicture}
    \begin{axis}
        \addplot gnuplot{x};
    \end{axis}
\end{tikzpicture}

\end{document}
