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?
Through the legend parameter set to false and by using the legend function and remove function, the seaborn legend can be easily removed.
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.
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.
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With