【发布时间】:2017-12-11 14:07:49
【问题描述】:
我不熟悉在 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()
【问题讨论】:
-
plt.legend()? -
谢谢@DavidG。这可行,但唯一的问题是我必须在最后单独做。所以像
plt.legend(['test_label1', 'test_label2'])这样的东西需要记住顺序。 -
您不必这样做,因为您已经在情节中指定了
label=。在plt.show()之前调用plt.legend()会起作用(对我有用)
标签: python matplotlib legend seaborn