Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to show legend in seaborn distplot

I am new to plotting in python and trying following code to plot distribution in seaborn but unable to see the legend, i.e., test_label1 and test_label1 on the plot.

import matplotlib.pylab as plt import seaborn as sns import numpy as np  plt.figure("Test Plots") lst1 = list(np.random.rand(10)) lst2 = list(np.random.rand(10)) sns.distplot(lst1, label='test_label1', color="0.25") sns.distplot(lst2, label='test_label2', color="0.25")  plt.show() 
like image 744
Rahul Avatar asked Jul 07 '17 10:07

Rahul


People also ask

How do you put the legend outside in Seaborn?

Set the figure size and adjust the padding between and around the subplots. Make a Pandas dataframe with three coulmns, column1, column2 and column3. Draw a scatterplot with possibility of several semantic groupings.


1 Answers

As you have already labelled your plots using label= inside your sns.distplot then all you have to do is show your legend. This is done by adding plt.legend() just before plt.show()

More information on matplotlib legends can be found in the documentation

like image 50
DavidG Avatar answered Sep 23 '22 06:09

DavidG