The answer to this question seems to suggest that one way to set legend font properties is through the following:
import pylab as plt
leg = plt.legend(framealpha = 0, loc = 'best')
for text in leg.get_texts():
plt.setp(text, color = 'w')
Which requires a call to plt.legend() and collects all the legends and does not distinguish between certain specific legends. In my code, I have several different plots. For example, dicts1 and dicts2 are dictionaries that contain dataframes:
def compare_data(dicts1, dicts2):
for dic in dicts1:
df = dic['df']
style = dic['style']
plt.plot(df['time'], df['y'], **style)
## style contains the legend text
## use the default font
for dic in dicts2:
df = dic['df']
style = dic['style']
plt.plot(df['time'], df['y'], **style)
## only modify the font color for the legends of these !!
# finally draw the legend with the common properties:
plt.legend(loc = 'best', frameon=False)
How do I modify the font color for the legends of only dict2 and not dict1 ? The values of legend color for dict1 remain as default values. The number of elements in both dictionaries is arbitrary.