TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to reference some plots (done with pgfplots) in my text but somehow it's not possible.

If i copypaste the examples from the pgfplot- documentation it works but if I move one of the labels to my plot it breaks while compiling the 2nd time (as long as the reference is rendered as "??" it's fine).

This is the error I get:

! Package pgfkeys Error: I do not know the key '/tikz/plot' and I am going to i
gnore it. Perhaps you misspelled it.

See the pgfkeys package documentation for explanation.
Type  H <return>  for immediate help.

l.105 Here the legend image \ref{pgfplots:plot2}
                                                 is displayed correctly.
Der Prozess wurde vom Benutzer abgebrochen

Referencing of the same plot in the legend works by the way.

 \begin{tikzpicture}[plot/.style={very thick,raw gnuplot,mark=none,black}]
 legend cell align=left, minor y tick num=3, minor x tick num=1, width=0.5\textwidth, domain=-pi/2:pi/2,
 ymin=0, ymax=1.3, xmin=-1.571, xmax=1.571, grid=both, y=5cm, axis y line=left, axis x line=bottom]
 \addplot gnuplot [plot,red]
     { ag1(x) = 0.33*sin(x);plot[-pi/2:pi/2]ag1(x)};
     \addlegendentry{$\delta_1=10 \ref{pgfplots:label3}$};
 \addplot gnuplot [plot,green]
     {ag1(x) =  0.33*cos(x);plot[-pi/2:pi/2]ag1(x)};
     \addlegendentry{$\delta_1=10 \ref{pgfplots:label4}$};
 \end{axis} \end{tikzpicture} \begin{tikzpicture}[baseline] \begin{axis}
 \addplot+ {3*x+2.5*rand};
 \addplot+[mark=none] {3*x};
 \addplot {4*cos(deg(x))};
    % \label{pgfplots:label3} %IF THIS LINE ISN'T A COMMENT IT WORKS
% \ref{pgfplots:label3}\\

So i have two pictures - if the label3 is in the lower picture it works, if it's in the other picture it doesn't compile.

share|improve this question
Can you please add to your question a minimal, complete document illustrating the problem? – Gonzalo Medina Jul 30 '13 at 13:13
I guess you put \label and/or \ref into the wrong line, but without seeing the code one can not tell. – sheß Jul 30 '13 at 13:28
added an example – oerpli Jul 30 '13 at 13:33
up vote 1 down vote accepted

Since you are referring the plot labelled pgfplots:label3 outside the plot and this was produced with the plot style, you need to declare this style globally; otherwise, having it only locally as in your code, the style isn't known outside the plot when the reference occurs:


plot/.style={very thick,raw gnuplot,mark=none,black}

legend cell align=left,
minor y tick num=3,
minor x tick num=1,
axis y line=left,
axis x line=bottom,
xlabel={$\varphi [^\circ]$},
\addplot gnuplot [plot,dashdotted]{
ag0(x) =    +0.330477   -2.06663*(x/pi)**2  +2.90481*(x/pi)**4  +0.296334*(x/pi)**6;
ag1(x) =    -0.398712   +3.35323*(x/pi)**2  -8.06845*(x/pi)**4  +4.13977*(x/pi)**6;
ag2(x) =    -0.1077     -0.990205*(x/pi)**2 +8.82304*(x/pi)**4  -12.5561*(x/pi)**6;
ag3(x) =    +0.226138   -0.545837*(x/pi)**2 -3.58968*(x/pi)**4  +8.61929*(x/pi)**6;
ag(x,y)=    ag0(x)+(log(y)/6)*(ag1(x)+(log(y)/6)*(ag2(x)+(log(y)/6)*(ag3(x))));
\addlegendentry{$\delta_1=10 $\ref{pgfplots:label3}};
\addplot+[only marks,
error bars/y dir=both,
error bars/y fixed=2.5]
\addplot+[mark=none] {3*x};
\addplot {4*cos(deg(x))};
%\label{pgfplots:label3} %NOW IT WORKS



enter image description here

share|improve this answer
Thanks a lot - it worked. – oerpli Jul 30 '13 at 14:02

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.