5
我是新来绘制python并试图跟随代码来绘制seaborn
中的分布,但无法看到图例上的图例,即test_label1
和test_label1
。无法在seaborn distplot中显示图例
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()
'plt.legend()'可以找到? – DavidG
谢谢@DavidG。这是有效的,但唯一的问题是我必须在最后单独执行。因此像'plt.legend(['test_label1','test_label2'])'需要记住排序。 – Rahul
您不必这样做,因为您已经在图中指定了'label ='。在'plt.show()'之前调用'plt.legend()'会工作(它对我来说) – DavidG