# Tikz external files and pdf

I plot graph in my article with the command '\begin{tikzpicture} ..\end{tikzpicture}'. First, I extract datas from matlab in a text file and I use \addplot with all the options. It is great, but my compilation is very very long ( I have a lot of figures ). Is it possible to have all the figures in tikz external files ( which I can modify sometimes ) and convert into a pdf file (because using \includegraphics with a pdf file is very fast) ?

You can process your tikzpictures as standalone documents and then include them as pictures. E.g., the file myplot.tex might contain

\documentclass[border=0.1cm]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[...]
...
\end{axis}
\end{tikzpicture}
\end{document}


Your main document then includes the generated pdfs:

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\includegraphics{myplot.pdf}
\end{document}


My advise is to put the tikz-code of your plots in separate files as it is easier to manage. I use an alias for \input to include these files just in case it requires special treatment later on.

\documentclass{article}
\newcommand{\tikzinput}[1]{%
\input{#1}%
}

\begin{document}
\tikzinput{myplot.tikz}
\end{document}


Second, you should use \tikzexternalize to speed up compilation. See the pgfplots manual: 7.1.1 Using the Automatic Externalization Framework of TikZ

\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{external}
\tikzexternalize% activate externalization!

\begin{document}
\begin{tikzpicture}
\begin{axis}