Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

matplotlib remove duplicate legend entries from plotting loop

def legend_without_duplicate_labels(ax):
    handles, labels = axes.get_legend_handles_labels()
    unique = [(h, l) for i, (h, l) in enumerate(zip(handles, labels)) if l not in labels[:i]]
    axes.legend(*zip(*unique))
legend_without_duplicate_labels(axes)
    
plt.show(); plt.close()

Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #matplotlib #remove #duplicate #legend #entries #plotting #loop
ADD COMMENT
Topic
Name
1+5 =