matplotlib custom legend with hatching

Viewed 6259

I can seem to figure out how to pass the handles and labels from matplotlib.patches.Patch to the legend.

import matplotlib.pyplot as plt
import matplotlib.patches as mpatches


a_val = 0.6
colors = ['#EA5739','#FEFFBE','#4BB05C']


circ1 = mpatches.Patch( facecolor=colors[0],alpha=a_val,hatch=['\\\\'],label='Label1')
circ2= mpatches.Patch( facecolor=colors[1],alpha=a_val,hatch='o',label='Label2')
circ3 = mpatches.Patch(facecolor=colors[2],alpha=a_val,hatch='+',label='Label3')

fig,(ax) = plt.subplots()

ax.legend(handles = [circ1,circ2,circ3],loc=2)
plt.tight_layout()

Why is the legend blank in the above example?

1 Answers
Related