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.

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 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

  /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 {

failes due to a compile error:

Undefined control sequence. [...] \pgfplotsplothandlermesh@numpoints ->\numcoords
share|improve this question
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:



  /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 {

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

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 {

(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


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.