[Tutor] Help with Matplotlib labels

Sean Carolan scarolan at gmail.com
Tue Jun 19 03:26:36 CEST 2012


> Unfortunately my graph is generated dynamically. How can I create my
> legend when my 'bar' objects have no names to refer to?
>
>    for admin in bd:
>        bar(ind, bd[admin], width, color=colordict[admin])
>    xticks(ind+width/2., datenames)
>    legend()
>    grid('on')
>    outfile = 'testfile.png'
>    savefig('/var/www/'+outfile)
>    return outfile

I found the solution to this problem, one of the optional kwargs for
the pyplyt.bar() function is "label".  Once I assigned that, legend()
worked fine.


More information about the Tutor mailing list