Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

   \documentclass{article}
 \usepackage{tikz,pgfplots}
 \begin{document}
 \begin{tikzpicture}[plot/.style={very thick,raw gnuplot,mark=none,black}]
 \begin{axis}[
 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)};
     \label{pgfplots:label4}
     \addlegendentry{$\delta_1=10 \ref{pgfplots:label3}$};
 \addplot gnuplot [plot,green]
     {ag1(x) =  0.33*cos(x);plot[-pi/2:pi/2]ag1(x)};
     \label{pgfplots:label3}
     \addlegendentry{$\delta_1=10 \ref{pgfplots:label4}$};
 \end{axis} \end{tikzpicture} \begin{tikzpicture}[baseline] \begin{axis}
 \addplot+ {3*x+2.5*rand};
     \label{pgfplots:label1}
 \addplot+[mark=none] {3*x};
     \label{pgfplots:label2}
 \addplot {4*cos(deg(x))};
    % \label{pgfplots:label3} %IF THIS LINE ISN'T A COMMENT IT WORKS
 \end{axis}
 \end{tikzpicture}
 \section{References}
 \ref{pgfplots:label1}\\
 \ref{pgfplots:label2}\\
% \ref{pgfplots:label3}\\
 \end{document}

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
2  
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
add comment

1 Answer 1

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:

\documentclass{article}
\usepackage{tikz,pgfplots}

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

\begin{document}
\begin{tikzpicture}[]
\begin{axis}[
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.57079632679,
xmax=1.57079632679,
grid=both,
y=5cm,
axis y line=left,
axis x line=bottom,
xlabel={$\varphi [^\circ]$},
ylabel=$a^{(c)}$]
\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))));
plot[-pi/2:pi/2]ag(x,100);
};
\label{pgfplots:label3}
\addlegendentry{$\delta_1=10 $\ref{pgfplots:label3}};
\end{axis}
\end{tikzpicture}\begin{tikzpicture}[baseline]
\begin{axis}
\addplot+[only marks,
samples=15,
error bars/y dir=both,
error bars/y fixed=2.5]
{3*x+2.5*rand};
\label{pgfplots:label1}
\addplot+[mark=none] {3*x};
\label{pgfplots:label2}
\addplot {4*cos(deg(x))};
%\label{pgfplots:label3} %NOW IT WORKS
\end{axis}
\end{tikzpicture}

\section{References}

\ref{pgfplots:label1}\\
\ref{pgfplots:label2}\\
\ref{pgfplots:label3}\\
\end{document}

enter image description here

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

Your Answer

 
discard

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.