Markers in legend?

Is it possible to include a marker from one or more

    > scatter plots in the legend? Robert

This is a bit tricky -- scatter plots can vary in size and color.
What should one use for the legend marker? So the short answer is no.
My question for you is, "how *should* it work?"

Not if you are using homogeneous marker sizes and colors, I suggest
using plot markers tweaking the properties, as in

  line, = plot(x,y,linestyle='None', marker='s',
               markerfacecolor='red', markeredgecolor='g',
               markersize=20, markeredgewith=3)

or the pithy

  line, = plot(x, y, ls='None', marker='s',
               mfc='red', mec='g', ms=20, mew=3)

These you can add to the legend.

  legend((line,), ('label',))

In matplotlib-0.72, this will be as fast or faster than scatter for
the agg backend. Probably faster.

If this is not an option -- eg you need variation in size but not
color, you can use a line as a stand-in in your legend. Create the
line, don't add it to the axes, but pass it to the legend

    sizes = 20*rand(len(x))
    scatter(x,y,s=sizes, marker='o', c='red')

    # now create the proxy line but don't add it to axes for drawing
    line = Line2D(x,y,marker='o', color='red')

    legend((line,), ('label',))

This is untested, so let me know how it goes...

JDH

John Hunter wrote:

    > Is it possible to include a marker from one or more
    > scatter plots in the legend?

This is a bit tricky -- scatter plots can vary in size and color.

Well, in my newbie-ness I wasn't aware that this was the case.

What should one use for the legend marker? So the short answer is no.
My question for you is, "how *should* it work?"

Not if you are using homogeneous marker sizes and colors, I suggest
using plot markers tweaking the properties, as in

  line, = plot(x,y,linestyle='None', marker='s', markerfacecolor='red', markeredgecolor='g',
               markersize=20, markeredgewith=3)

For me, this is exactly how it should work - thanks!

Robert