Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove Seaborn barplot legend title

Tags:

I use seaborn to plot a grouped bar plot as in https://seaborn.pydata.org/examples/factorplot_bars.html

Giving me: https://seaborn.pydata.org/_images/factorplot_bars.png

there is a title (sex) on the legend which I would like to remove.

How could I achieve that?

like image 601
hangc Avatar asked Apr 01 '17 00:04

hangc


People also ask

How do you get rid of the legend in Seaborn plot?

Through the legend parameter set to false and by using the legend function and remove function, the seaborn legend can be easily removed.

How do I edit my legend in Seaborn?

To change the position of a legend in a seaborn plot, you can use the plt. legend() command. The default location is “best” – which is where Matplotlib automatically finds a location for the legend based on where it avoids covering any data points.

How do I change my legend color in Seaborn?

Just with the use of matplotlib. pyplot. set_facecolor() function from matplotlib library and pass the name of the color user want to in the seaborn legends.


1 Answers

This may be a hacky solution but it works: if you tell Seaborn to leave it off at the time of plotting and then add it back it doesn't have the legend title:

g = sns.factorplot(x='Age Group',y='ED',hue='Became Member',col='Coverage Type',                    col_wrap=3,data=gdf,kind='bar',ci=None,legend=False,palette='muted') #                                                         ^^^^^^^^^^^^ plt.suptitle('ED Visit Rate per 1,000 Members per Year',size=16) plt.legend(loc='best') plt.subplots_adjust(top=.925) plt.show() 

Example result:

enter image description here

like image 172
mechanical_meat Avatar answered Sep 16 '22 20:09

mechanical_meat