The following MWE without TikZ externalization works. However, the legend at the bottom is lost with externalization. Since the \ref in this example does not refer to anything outside tikzpicture environment, I thought this should work. However, I understand that latex needs to loop twice to resolve the reference and is not able to do it here.
MWE:
\documentclass{standalone}
\usepackage{tikz,pgfplots}
\pgfplotsset{compat=1.6}
\usetikzlibrary{external}
\tikzexternalize
\begin{document}
\begin{tikzpicture}
\begin{axis}[%
legend entries={$\sin(x)$},
legend to name = named,
name = plt
]
\addplot {sin(deg(x))};
\end{axis}
\node[at=(plt.south),anchor=north] {\ref{named}};
\end{tikzpicture}
\end{document}
If I move \ref{named} outside the tikzpicture environment, I can generate two separate PDF files using list and make mode. However, I would like to keep the legends with my plot.
PS: MWE is only representative. This will be used for legend entries with multiple subplots.
\pgfplotslegendfromname{name}instead of\ref{name}? I figured it out, but didn't know how to let people know. – devendra Dec 07 '12 at 19:31