2021年1月18日星期一

Overriding Seaborn legend

I made a line plot using seaborn's relplot and I wanted to customize my legend labels. For some reason when I do this, It creates another legend with out deleting the old one. How do I get rid of the initial legend (The legend with title "Sex")? Also how do I add a legend title to my new legend?

Here is the code I used to generate my plot:

  plt.figure(figsize=(12,10))    sns.relplot(x='Year',y = 'cancer/100k pop' , data = dataset_sex,hue="Sex", kind="line",ci=None)  title_string = "Trend of Cancer incidencies by Sex "   plt.xlabel('Years')  plt.title(title_string)  plt.legend(['Men','Women'])    

enter image description here

https://stackoverflow.com/questions/65784578/overriding-seaborn-legend January 19, 2021 at 10:05AM

没有评论:

发表评论