5

I'm having a few issues with creating a legend in the caption of an image. I've made a lot of graphs using matlab2tikz and I've externalised them to reduce my compiling time and memory usage. Consequently, I can't then use any \labels in the code. So I'm making a TikZ plot immediately below it and using those line styles in the caption. A MWE is displayed below:

\begin{tikzpicture}
\begin{axis}[hide axis]
\addplot [color=red,solid,forget plot]
(0,0);\label{hwplot1}
\addplot[color=brown,solid,mark=o,mark options={solid},forget plot]
(0,0);\label{Blomhoff}
\end{axis}
\end{tikzpicture}

I then call the label in the caption and everything works a ok. The issue that arises is that I get a brown dot at what TikZ defines at (0,0), which is the mark, and I can't find a way of getting rid of this. Is there a way I can do this? Or an alternative method of putting the legend in the caption that allows for externalization?
Thanks in advance

Stefan Pinnow
  • 29,535
James
  • 61
  • You might be interested in http://tex.stackexchange.com/questions/54794/using-a-pgfplots-style-legend-in-a-plain-old-tikzpicture – John Kormylo Oct 20 '14 at 13:28
  • 1
    The external library allows references to labels in external files -- but not together with the default system call. Do you use windows or unix? Unix users can typically use make to get this without any problems. – Christian Feuersänger Oct 20 '14 at 18:38
  • You should have a look at this link: http://tex.stackexchange.com/questions/20926/tikz-legend-in-caption – pluton Nov 01 '16 at 10:57

1 Answers1

3

Maybe something has changed in PGFPlots since you have asked the question, but today you can just \ref \labeled \addplots and you get the desired output.

Here I just wrote a dummy caption where you I \refed the labels. Hopefully this answers your question, because I am not 100% sure that I have understood it right.

% used PGFPlots v1.14
\documentclass[border=5pt,varwidth]{standalone}
\usepackage{pgfplots}
    \usetikzlibrary{
        pgfplots.external,
    }
    \tikzexternalize[
        % prevent externalization of none named figures/plots
        % (that means that in this case the `\ref's will not be externalized)
        only named=true,
    ]
\begin{document}
    \tikzsetnextfilename{just_a_test}
    \begin{tikzpicture}
        \begin{axis}
            \addplot coordinates {(0,0) (1,1)};
                \label{hwplot1}
            \addplot+ [color=green,solid,mark=o,mark options={solid},dashed]
                coordinates {(0.1,0) (1.1,1)};
                \label{Blomhoff}
        \end{axis}
    \end{tikzpicture}

    Figure~1: This is a test plot only, where \ref{hwplot1} shows a blue line
    and \ref{Blomhoff} shows a green line
\end{document}

image showing the result of above code

Stefan Pinnow
  • 29,535
  • May I ask why the images that will make the reference shall not be externalized? Indeed, I use externalization very heavily and I'd prefer not to give a name to all the figures I already have. Is there another way to do that? – Alessandro Cuttin Feb 15 '18 at 15:20
  • @AlessandroCuttin, I am not 100% sure what your question is all about. Of course you can also export the \ref pictures, but I think they are created that fast that there is no need to do so. Externalization normally is all about saving time for "expensive" figures. (As a matter of taste I like to name them accordingly so I reuse them elsewhere. There of course it is beneficial to have a clear name. And thus I don't like the generic names of non-named to be externalized figures.) – Stefan Pinnow Feb 15 '18 at 19:17
  • @AlessandroCuttin, so the question is, what do you mean with "Is there another way to do that?"? – Stefan Pinnow Feb 15 '18 at 19:18
  • I asked because externalizing all the figures (including the labels) results in one or more errors. I wondered if another way existed to which figures can be externalized and which not, other than assigning a name and using the only named flag – Alessandro Cuttin Feb 15 '18 at 19:26
  • Sorry, but commenting only named=true and \tikzsetnextfilename{just_a_test} works perfectly fine for me. I then get minimal-figure0, minimal-figure_crossref0 and minimal-figure_crossref1. Each a DPTH, LOG, MD5, and PDF file. – Stefan Pinnow Feb 15 '18 at 20:18
  • ok, thanks! that's good to know. Maybe what I experience is caused by the fact that I already have a particularly convoluted document (already had issues with externalize before) – Alessandro Cuttin Feb 16 '18 at 09:55