# Pgfplot Externalize & Trim Axes

I've recently run into a pickle. I like to use pgfplots to create figures in my reports. Occasionally I have enough figures that I'd like to use the externalize option of pgfplots. This means the figure gets created as a standalone PDF (but it inherits all the settings from the master tex file) that I can then import as a PDF into the final file. It avoids having to wait for the compiler to create each figure each time the document is compiled.

However, I also like to use the trim axis left and right. It seems I cannot combine the use of externalize along with the trim axis options.

Here is a simplified example. Let's say I have a paper and I want to include a plot of sin(x) and cos(x). I also want to use the externalize option of pgfplots so I can compile the plots separately from the rest of the paper. I am using the subfiles package so that the tex files inherit all the settings and characteristics of my master file.

\documentclass[../../TeX/Project1.tex]{subfiles}
\usepgfplotslibrary{external}
\tikzexternalize
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xlabel = My X Axis,
ylabel = My Y Axis
]
\end{axis}
\end{tikzpicture}
\end{document}

\documentclass[../../TeX/Project1.tex]{subfiles}
\usepgfplotslibrary{external}
\tikzexternalize
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xlabel = My X Axis,
ylabel = My Y Axis
]
\end{axis}
\end{tikzpicture}
\end{document}


And from the main tex file:

\begin{figure}[H]
\centering
\begin{minipage}[t]{0.4\textwidth}
\centering
\includegraphics[scale=0.7]{../Figures/SineFigTest/SineFig-figure0.pdf}
\captionof{figure}{My First Figure Caption}
\label{P1:SinPlot}
\end{minipage}\hspace{0.60in}
\begin{minipage}[t]{0.4\textwidth}
\centering
\includegraphics[scale=0.7]{../Figures/CosFigTest/CosFig-figure0.pdf}
\captionof{figure}{My Second Figure Caption}
\label{P1:CosPlot}
\end{minipage}
\end{figure}


I'd like to include these plots side-by-side in the paper and I want them to be centered based on the sides of the plots not including the y-axis labels. The only way I can tell to accomplish this is to compile the figures as part of the paper itself (i.e. avoid using externalize) and using the trim axis left and trim axis right options of tikzpicture.

My question is whether or not it is possible to externalize the plots and still achieve the effect of the trim axis options?

If you have any other suggestions or ideas more generally based on the snippets I've included above on how to improve my tex-ing I'd love to know.

Hopefully this makes my questions more clear. If not please let me know and perhaps I will delete and re-think on how to submit this.

• I am not 100% sure if I understand your question right, and because you didn't get an answer so far, I guess I am not the only one. Could you add a sketch or some screenshots to the question? I guess this will help a lot to clarify what you want. Thanks. – Stefan Pinnow Apr 7 at 17:12
• Thank you for the feedback. I've updated the question with an example. – Nukesub Apr 14 at 17:32