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 use a mesh plot with scatter points (2d) where the colors are determined from a third coordinate of the data as described in this question. The legend however should contain the markers of a curve as icon (not that miniature mesh). How can I achieve that?

Edit: the problems seems to be with legend image code in line legend that does not draw correctly with mesh settings. How do I have to modify a custom legend image code to simply display the current marker in a fixed color (say black)?

My attempt so far

\pgfplotsset{
  /pgfplots/pplots legend/.style={
  legend image code/.code={   
    \draw[color=black] (0cm,0cm) to (0.6cm,0cm);
    \draw[#1,color=black,mark repeat=1,mark phase=1]
      plot coordinates {
      (0.3cm,0cm)
    };
  }}}

failes due to a compile error:

Undefined control sequence. [...] \pgfplotsplothandlermesh@numpoints ->\numcoords
share|improve this question

1 Answer 1

up vote 5 down vote accepted

With the settings above, the legend inherits the current settings of the plot (which is typically desired). In your case, you need to override the plot handler explicitly by providing sharp plot (or maybe only marks?) to the legend's option list:

\documentclass{article}

\usepackage{pgfplots}

\begin{document}
\thispagestyle{empty}
\pgfplotsset{
  /pgfplots/pplots legend/.style={
  legend image code/.code={   
    \draw[color=black] (0cm,0cm) to (0.6cm,0cm);
    \draw[sharp plot,mark=*,color=black,mark repeat=1,mark phase=1]
      plot coordinates {
      (0.3cm,0cm)
    };
  }}}

\begin{tikzpicture}
    \begin{axis}[legend entries=$x^2y^2$]
    \addplot3[surf,pplots legend] {x^2*y^2};    
    \end{axis}
\end{tikzpicture}
\end{document}

enter image description here

Are you sure that you want the \draw[color=black] ... to ; statement in your legend image code? You can probably replace it by

/pgfplots/pplots legend/.style={%
    /pgfplots/legend image code/.code={%
        \draw[mark repeat=2,mark phase=2,black,sharp plot] 
            plot coordinates {
                (0cm,0cm) 
                (0.3cm,0cm)
                (0.6cm,0cm)%
            };%
    }%
},  

(which is the default line legend, by the way)

share|improve this answer
    
Exactly what I was looking for, thank you! –  dcn Nov 3 '11 at 20:20

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.