I've used tikz to build all the charts in a manuscript I'm preparing for submission to a journal. As a last step prior to submission, I wanted to take all the tikz code out and just \includegraphics the externalized graphic files. The problem is that several of my graphics are groupplots where several plots share a common legend. I've accomplished this using legend to name=xxx
and then placing \ref{xxx}
after the figure. Here's an example. If you want to build it yourself the data is here and here
\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\usetikzlibrary{pgfplots.groupplots}
\usetikzlibrary{plotmarks}
\usetikzlibrary{patterns}
\usepgfplotslibrary{external}
\tikzexternalize
\pgfplotsset{compat = 1.12}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{groupplot}[
group style={group size=2 by 1,
xlabels at=edge bottom,
ylabels at=edge left},
xlabel = {\footnotesize $\alpha_{++}$},
ylabel = {\footnotesize Departure Rate},
view={0}{90},
colorbar horizontal,
colorbar to name=ContourColorbar,
colormap/blackwhite,
y tick label style={/pgf/number format/.cd,
fixed,
fixed zerofill,
precision=2,
/tikz/.cd},
x tick label style={/pgf/number format/.cd,
fixed,
fixed zerofill,
precision=0,
/tikz/.cd}]
\nextgroupplot[title={\scriptsize Come and Go}]
\addplot3[surf, shader=interp,colormap/blackwhite] file {ComeAndGoSurface.txt};
\nextgroupplot[title={\scriptsize ++Resources}]
\addplot3[surf, shader=interp,colormap/blackwhite] file {PPResourcesSurface.txt};
\end{groupplot}
\end{tikzpicture}
\ref{ContourColorbar}
\caption{++Resources and Come and Go}
\label{HeatMap}
\end{figure}
\end{document}
This code produces the following document, which is fine.
But the externally generated image is this
Note, no colorbar.
The TikZ manual 50.4.1 offers this advice if there is a \ref inside of externalized graphics:
"Thus: if you have \ref inside of external graphics, consider using mode=list and make or copy-paste the system call for the image(s) and issue it manually."
At this point I'm out of my depth. I'm using MikTex and TexNicCenter and that's the only way I've ever used Latex. I'm not really sure what "using mode=list and make or copy-paste the system call" even means. Is there a guide someone could point me to that spells this out? I did try some googling and found some references to using Make, but again I have no experience with this.
Alternatively, is there another method to achieve a single legend in a groupplot that avoids the \ref in the externalized image? I have several of these in this document in addition to the one shown here.
Thanks!
Addition: As I try to figure this out, I found this question whose answer boiled down to
Add
\pgfkeys{
/tikz/external/mode=list and make
}
And then run make -B -f <filename>.makefile
after the first compile run
So I download GNU make and tried this. After the first compile run, there is indeed a file called MWE.makefile. From the command prompt, I ran make -B -f MWE.makefile
and I get the following output
process_begin: CreateProcess(NULL, cat mwe.figlist, ...) failed.
process_begin: CreateProcess(NULL, cat mwe.figlist, ...) failed.
All images exist now. Use make -B to re-generate them.
The resulting pdf file looks like this
So....any suggestions on how to proceed? Am I doing something wrong? Are there issues with make on a windows system?
Second addition: I'm piling on the questions here as I try to puzzle this out. I can't imagine I'm the first person to encounter this...maybe I'm just really dumb.
In another post here I found a very similar problem, just not using a groupplot. The solution involved inserting a node and replacing the \ref. Combing the MWE from that post with the changes provided in its answer provides the following code.
\documentclass{standalone}
\usepackage{tikz,pgfplots}
\pgfplotsset{compat=1.12}
\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] {\pgfplotslegendfromname{named}};
\end{tikzpicture}
\end{document}
I thought I had my answer...except that I can't figure out how to "name" a groupplot. You'll note in the above code the line name = plt
in the axis environment. This allows you to later use node[at=(plt.south)
. Although the manual indicates that the groupplot environment should function basically the same as the axis environment, I can't figure out how to achieve that naming. And so I when I try to build I get No shape named plt is known
. So if anyone knows how THAT can be accomplished then maybe that's my answer...
Third edit, I guess it's a process. Above I said I'd been unable to name a group plot. Figured that one out, but still no joy. Code now looks like this
\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\usetikzlibrary{pgfplots.groupplots}
\usetikzlibrary{plotmarks}
\usetikzlibrary{patterns}
\usepgfplotslibrary{external}
\tikzexternalize
%\pgfkeys{/tikz/external/mode=list and make}
\pgfplotsset{compat = 1.12}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{groupplot}[group style={group size=2 by 1,
group name = plots,
xlabels at=edge bottom,
ylabels at=edge left},
xlabel = {\footnotesize $\alpha_{++}$},
ylabel = {\footnotesize Departure Rate},
view={0}{90},
colorbar horizontal,
colorbar to name=ContourColorbar,
colormap/blackwhite,
y tick label style={
/pgf/number format/.cd,
fixed,
fixed zerofill,
precision=2,
/tikz/.cd
},
x tick label style={
/pgf/number format/.cd,
fixed,
fixed zerofill,
precision=0,
/tikz/.cd
}]
\nextgroupplot[title={\scriptsize Come and Go}]
\addplot3[surf, shader=interp,colormap/blackwhite] file {ComeAndGoSurface.txt};
\nextgroupplot[title={\scriptsize ++Resources}]
\addplot3[surf, shader=interp,colormap/blackwhite] file {PPResourcesSurface.txt};
\end{groupplot}
\node[at=(plots c2r1.south),anchor=north] {\pgfplotslegendfromname{ContourColorbar}};
\end{tikzpicture}
%\ref{ContourColorbar}
\caption{++Resources and Come and Go}
\label{HeatMap}
\end{figure}
\end{document}
And the output looks like this
I'm guessing the ?? is my node with no colorbar.
external
library in thestandalone
document? Does it have to do with compiling the standalone-.tex
in the figures subfolder?