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?
colors() This function is used to specify the color.
plt. show() starts an event loop, looks for all currently active figure objects, and opens one or more interactive windows that display your figure or figures. The plt. show() command does a lot under the hood, as it must interact with your system's interactive graphical backend.
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')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With