Impossible to show the legend in the sea word

I am new to building in python and trying to execute the following code to build distribution in seaborn , but could not see the legend, i.e. test_label1 and test_label1 on the chart.

 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() 
+23
source share
2 answers

Since you have already indicated your graphs with label= inside your sns.distplot all you have to do is show your legend. This is done by adding plt.legend() immediately before plt.show()

More information on Matplotlib legends can be found in the documentation.

+39
source
 import seaborn as sns import matplotlib.pyplot as plt fig = plt.figure(figsize=(10,6)) lst1 = list(np.random.rand(10)) lst2 = list(np.random.rand(10)) sns.distplot(lst1) sns.distplot(lst1) fig.legend(labels=[test_label1 ,test_label2]) plt.show() 
0
source

Source: https://habr.com/ru/post/1269600/


All Articles