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

Scott Lasley selasley at icloud.com
Wed May 22 17:43:17 EDT 2019


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

> On May 22, 2019, at 2:34 PM, Bruno Pagani <bruno.pagani at astrophysics.eu> wrote:
> 
> Hi,
> I’ve stumbled upon this very exact issue, for which there is no posted
> answer:
> https://stackoverflow.com/questions/26573864/matplotlib-get-errorbar-color-from-legend
> Does anyone have an idea?
> Regards,
> Bruno


More information about the Matplotlib-users mailing list