Search
 
SCRIPT & CODE EXAMPLE
 

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()

Comment

PREVIOUS NEXT
Code Example
Python :: python PyDrive service account credentials 
Python :: jointplot title 
Python :: Python How to get the keys in a dictionary? 
Python :: delete variable python 
Python :: how to input data to the list in pythion 
Python :: python re.search() 
Python :: monty hall problem in python 
Python :: f-string print 
Python :: divide every element in numpy array 
Python :: pandas line plot dictionary 
Python :: python 2d dictionary 
Python :: addition of array in python with input 
Python :: list to dataframe columns 
Python :: python read file xlsx and return a list 
Python :: how to use css in php example 
Python :: random letters generator python 
Python :: sns histplot 
Python :: chrome profiles user open with python 
Python :: register admin django 
Python :: python backslash in string 
Python :: find all unique substring permutations of a string of a specific length python 
Python :: python add commas to list 
Python :: Error: getaddrinfo ENOTFOUND www.python.org www.python.org:443 Downloading Python failed. Error: { Error: getaddrinfo ENOTFOUND www.python.org www.python.org:443 
Python :: create new list with for loop python 
Python :: open and write in a file in python 
Python :: scree plot sklearn 
Python :: numpy concatenation 
Python :: concact geodataframe python 
Python :: how to make a username system using python 
Python :: python find center of polygon function 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =