matplotlib legend text code example

Example 1: legend size matplotlib

plt.plot([1, 2, 3], label='Inline label')
plt.legend(loc=1, prop={'size': 16})

Example 2: change text in legend matplotlib

plt.plot(range(10), label='Some very long label')
plt.plot(range(1,11), label='Short label')
L=plt.legend()
L.get_texts()[0].set_text('make it short')
plt.savefig('temp.png')

Example 3: python no label in legend matplot

ax.plot(randn(1000).cumsum(), 'k.', label='_nolegend_')

Example 4: legend text color matplotlib

import matplotlib.pyplot as plt
l = plt.legend()
for text in l.get_texts():
    text.set_color("red")