[Matplotlib-users] Get color from legend for errorbar plots

Paul Hobson pmhobson at gmail.com
Thu May 23 09:28:20 EDT 2019


Hey Bruno,

In this case, I believe `lc` is a LineCollection, so it's essentially a
sequence of N lines. In this case, it appear N = 1.
-p

On Thu, May 23, 2019 at 3:34 AM Bruno Pagani <bruno.pagani at astrophysics.eu>
wrote:

> Le 22/05/2019 à 23:43, Scott Lasley a écrit :
> > As Tom Caswell pointed out, you can use the legendHandles.  Something
> like this may do what you want
> >
> > plt.errorbar([1,2,3],[1,2,3],yerr=0.2,label='22')
> > plt.errorbar([3,1,2],[2,3,1],yerr=0.3,label='33')
> > z  = plt.legend()
> > [lc.get_colors() for lc in z.legendHandles]
> >
> > hth,
> > Scott
>
> Note that for some reason lc.get_colors() returns array of color in rgba
> format, e.g. [[r g b a]]. So I had to do lc.get_colors()[0] instead, but
> then it works fine.
>
> Thanks for your help,
> Bruno
>
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users at python.org
> https://mail.python.org/mailman/listinfo/matplotlib-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20190523/18e84cd5/attachment.html>


More information about the Matplotlib-users mailing list