[Matplotlib-users] bar graph and legend

 [Matplotlib-users] bar graph and legend From: Gianluca Santarossa - 2007-09-14 07:24:24 ```Dear all, I am an unexperienced matplotlib user, and I have a couple of questions about adding a legend to a graph. In this example, on my PC both the entries in the legend appear in blue color: #!/usr/bin/env python import numarray as na from pylab import * labels = ["A", "B", "C"] first = [ 1, 2, 3 ] second = [ 3, 2, 1 ] xlocations = na.array(range(len(labels)))+0.33 width = 0.33 bar1=bar(xlocations, first, width=width, color='blue') bar2=bar(xlocations+.33, second, width=width, color='red') legend((bar1,bar2), ('First','Second')) show() Did I make some mistake? 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? Thank in advance, Gianluca ```

 [Matplotlib-users] bar graph and legend From: Gianluca Santarossa - 2007-09-14 07:24:24 ```Dear all, I am an unexperienced matplotlib user, and I have a couple of questions about adding a legend to a graph. In this example, on my PC both the entries in the legend appear in blue color: #!/usr/bin/env python import numarray as na from pylab import * labels = ["A", "B", "C"] first = [ 1, 2, 3 ] second = [ 3, 2, 1 ] xlocations = na.array(range(len(labels)))+0.33 width = 0.33 bar1=bar(xlocations, first, width=width, color='blue') bar2=bar(xlocations+.33, second, width=width, color='red') legend((bar1,bar2), ('First','Second')) show() Did I make some mistake? 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? Thank in advance, Gianluca ```
 Re: [Matplotlib-users] bar graph and legend From: - 2007-09-14 07:44:13 ```Gianluca Santarossa 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]: [] In [7]: legend(_, ('foo',), numpoints=1) Out[7]: -- Jouni K. Seppänen http://www.iki.fi/jks ```
 Re: [Matplotlib-users] bar graph and legend From: Gianluca Santarossa - 2007-09-14 07:47:21 ```> 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 ```

JavaScript is required for this form.

No, thanks