Pylab errorbar and legend

Legend() works great when you’re using plot, but when you use errorbar the auto-generated legend seems to include bar and/or cap lines for the error bars, making it unusable.

I fixed this once a long time ago by making the legend command skip any lines without labels. It was kind of a hack…

Having installed the latest version on my new MacBook Pro, I found a better way to fix the problem too. In the errorbar method of Axes I added label=‘nolegend’ to the plotting commands. If a developer would like to add it, here are my modified lines 1577-1580 and 1590-1593 of

barlines.extend( self.hlines(y, x, left,label=‘nolegend’) )

barlines.extend( self.hlines(y, x, right,label=‘nolegend’) )

caplines.extend( self.plot(left, y, ‘|’, ms=2*capsize,label=‘nolegend’) )

caplines.extend( self.plot(right, y, ‘|’, ms=2*capsize,label=‘nolegend’) )

barlines.extend( self.vlines(x, y, upper,label=‘nolegend’ ) )

barlines.extend( self.vlines(x, y, lower,label=‘nolegend’ ) )

caplines.extend( self.plot(x, lower, ‘_’, ms=2*capsize,label=‘nolegend’) )

caplines.extend( self.plot(x, upper, ‘_’, ms=2*capsize,label=‘nolegend’) )


Robb Brown

Biomedical Engineering

University of Calgary

Calgary, Alberta, Canada