# How to reference plot in legend?

I want to reference a plot in the legend. The problem is, that the little legend image from the blue plot is shown distorted in the legend.

Here a minimal example:

\documentclass{minimal}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot[color=red] coordinates {(1, 1) (2, 200)};
\addlegendentry{plot 1 (\ref{pgfplots:plot2} xy added)}

\addplot[color=blue, mark=x, forget plot] coordinates {(2, 200) (2.5, 100) (3, 50)};
\label{pgfplots:plot2}

\addplot[color=red, forget plot] coordinates {(3, 50) (4, 100)};
\end{axis}
\end{tikzpicture}\\
Here the legend image \ref{pgfplots:plot2} is displayed correctly.
\end{document}


How is it possible to fix this? Thanks for your time.

-
I suspect this is a bug in pgfplots: consider reporting it via the e-mail address given in the package documentation. –  Joseph Wright Jul 21 '12 at 6:31

## 1 Answer

It is a bug in pgfplots 1.5.1 (the current stable).

I will take care of it (the \tikzifinpicture macro shipped with tikz needs to be fixed).

-