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.

When I use \label and \ref to distinguish two y axes the marks drawn by \ref are no longer on the lines after rotating it together with the rest of the label (see example below). Any ideas?

\documentclass{article}

\usepackage{pgfplots}

\begin{document}
  \begin{tikzpicture}
    \begin{axis}[axis y line*=left, scale only axis,
                 ylabel={estimation 2 \ref{pgf:allsamples}}]
      \addplot[blue,mark=+] table {data2.csv};
      \label{pgf:allsamples}
    \end{axis}
    \begin{axis}[axis y line*=right, scale only axis,
             ylabel={estimation 1 \ref{pgf:swingvotes}}, ylabel near ticks]
      \addplot[red,mark=x] table {data1.csv};
      \label{pgf:swingvotes}
    \end{axis}
  \end{tikzpicture}
\end{document}

ref does not work as expected

share|improve this question
    
Can you edit your question and elaborate on "something went wrong". –  Peter Grill Dec 2 '11 at 18:34
    
Yep, that description was a bit weak, I hoped the picture would make clear what I mean. Anyway, Christian's patch did exactly what I wanted. I changed the description a bit so hopefully if anyone else has the same problem they will find this with google. –  Flogo Dec 3 '11 at 12:50
add comment

1 Answer

up vote 7 down vote accepted

There is, indeed, a bug in pgfplots: the \ref command checks if "it is invoked from within a tikz picture". But this check is buggy because it, well is invoked from within a tikzpicture, but the tikzpicture has been interrupted to display a node.

As a result of the bug, the labels have an unexpected displacement.

Until the bug is fixed, you can use the following work-around:

\documentclass{article}

\usepackage{pgfplots}

\def\fixcheck{%
    \def\tikzifinpicture##1##2{##2}%
}%

\begin{document}
  \begin{tikzpicture}
    \begin{axis}[axis y line*=left, scale only axis,
                 ylabel={\fixcheck estimation 2 \ref{pgf:allsamples}}]
      \addplot[blue,mark=+] {x+5};
      \label{pgf:allsamples}
    \end{axis}
    \begin{axis}[axis y line*=right, scale only axis,
             ylabel={\fixcheck estimation 1 \ref{pgf:swingvotes}}, ylabel near ticks]
      \addplot[red,mark=x] {x};
      \label{pgf:swingvotes}
    \end{axis}
  \end{tikzpicture}
\end{document}

In all your labels, it adds the \fixcheck macro which will simply cause the check to return "false". In that case, \ref will add a temporary tikzpicture.

share|improve this answer
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.