I am using FontAwesome in my chart, and each data point is a symbol in FontAwesome font, displaying like an icon. Therefore, in the legend, I would like to use text (symbols in FontAwesome) to describe the items.
The code I am using is like:
from matplotlib.patches import Patch
import matplotlib.pyplot as plt
import matplotlib.font_manager as fm
ax = plt.gca()
ax.axis([0, 3, 0, 3])
prop = fm.FontProperties(fname='FontAwesome.otf', size=18)
ax.text(x=0, y=0, s='\uf1c7', color='r', fontproperties=prop)
ax.text(x=2, y=0, s='\uf050', color='g', fontproperties=prop)
plt.legend(handles=[Patch(color='r', label='label1'), Patch(color='g', label='label2')])
So what I want to do is to replace the color bar in the legend to the same icons as it in the plot.
The handle I am using is a list of Patches. But I found that it's hard to add text into Patch. I found there's a great solution to add picture into legend here: Insert image in matplotlib legend
I have tried using TextArea replacing BboxImage in that answer, but it doesn't work, and TextArea doesn't support fontproperties like axis.text.
So is there a way I can use text instead of markers in the legend?