You can also do this with setp ():
import pylab as plt leg = plt.legend(framealpha = 0, loc = 'best') for text in leg.get_texts(): plt.setp(text, color = 'w')
this method also allows you to set the font and any number of other font properties on one line (here: http://matplotlib.org/users/text_props.html )
full example:
import pylab as plt x = range(100) y1 = range(100,200) y2 = range(50,150) fig = plt.figure(facecolor = 'k') ax = fig.add_subplot(111, axisbg = 'k') ax.tick_params(color='w', labelcolor='w') for spine in ax.spines.values(): spine.set_edgecolor('w') ax.plot(x, y1, c = 'w', label = 'y1') ax.plot(x, y2, c = 'g', label = 'y2') leg = plt.legend(framealpha = 0, loc = 'best') for text in leg.get_texts(): plt.setp(text, color = 'w') plt.show()
wordsforthewise
source share