I'm trying to get the text in my legend to match the color of the lines from the plot. There is a nice summary of how to do this by Dan, over here: Matplotlib: Color-coded text in legend instead of a line
However, it does not seem to work for errorbar plot types. Does anyone have an idea of what handle I should use to make this change?
Here's some example code that shows how it works with the plot type element, but doesn't work with the errorbar type element:
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(0.1,4,0.5)
y1 = np.exp(-x)
y2 = np.exp(-x)*1.2+0.25
plot = plt.figure()
ax = plot.add_axes([0,0,1,1])
ax.plot(x,y1,color="red",label="Y1")
ax.errorbar(x,y2,yerr=0.1,color="blue",marker='*',capsize=4,label="Y2")
leg = ax.legend();
for line, text in zip(leg.get_lines(), leg.get_texts()):
text.set_color(line.get_color())
And here's an example of how that plot looks:
Code will change text color of plot types but not errorbar types
Thanks for any advice!
