bar graph and legend

Gianluca Santarossa
<gianluca.santarossa@...1726...> writes:

In this example, on my PC both the entries in the legend appear in blue
color:

legend((bar1,bar2), ('First','Second'))

You want legend((bar1[0],bar2[0]), ('First','Second')). What happened
was that matplotlib made a legend entry for two of the blue bars in
bar1; it would have made six entries, but stopped because you only gave
it two labels.

Moreover, if I add a legend to a graph plotting a set with marks and
without lines, the legend will show two points instead of one (which
would have been the expected behaviour). Is this correct?

I get four points, not two, but perhaps this has changed in the svn
version. At least in the svn version you can control the number of
points with the numpoints keyword argument:

In [6]: plot([3,1,4,1,5,9,2,6,5,3,5],'bo')
Out[6]: [<matplotlib.lines.Line2D instance at 0x16cf9b98>]

In [7]: legend(_, ('foo',), numpoints=1)
Out[7]: <matplotlib.legend.Legend instance at 0x16cf9bc0>

···

--
Jouni K. Sepp�nen

You want legend((bar1[0],bar2[0]), ('First','Second')). What happened
was that matplotlib made a legend entry for two of the blue bars in
bar1; it would have made six entries, but stopped because you only gave
it two labels.

Dear Jouni,
thanks for all the answers.
Gianluca