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:
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')