我刚开始用python绘图,并尝试用下面的代码在seaborn
中绘制分布图,但看不到图例,即test_label1
和test_label1
。
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()
因为您已经在
sns.distplot
中使用label=
标记了绘图,所以您所要做的就是显示图例。这是通过在plt.show()
之前添加plt.legend()
来完成的有关matplotlib图例的更多信息,请参见documentation
相关问题 更多 >
编程相关推荐