How can I get the color of the last figure in matplotlib?

后端 未结 1 635
梦谈多话
梦谈多话 2021-01-11 11:23

I\'m plotting some data sets with linear fits. I want the linear fit to have the same color as the plotted data (error bars). How can I get that color?

相关标签:
1条回答
  • 2021-01-11 11:44

    You might try this:

    x = np.arange(10)
    y = np.arange(10)
    err = np.ones(10)
    ebar = plt.errorbar(x,y, yerr=err)
    color = ebar[0].get_color()
    

    ebar is a container of artist, so you might modify the index in the last line to match the artist you want to get color from.

    You can also easily set the color of the errorbar, so you know exactly what color they are without checking it:

    ebar = plt.errorbar(x,y, yerr=err, ecolor='y')
    
    0 讨论(0)
提交回复
热议问题