matplotlib:带有传奇的散点图作为类的字符串
绘制二元分类的散点分布['cat', 'dog']
:
X, y = make_classification(n_samples=1000, n_features=2, n_redundant=0,
n_clusters_per_class=1, weights=[0.9], flip_y=0, random_state=1,)
counter = Counter(y)
for label, _ in counter.items():
row_ix = np.where(y == label)[0]
plt.scatter(X[row_ix, 0], X[row_ix, 1], label=label)
plt.legend()
plt.show()
输出:
我想替换 0
、1
传说与猫
、狗
。我在这里:
for label, _ in counter.items():
row_ix = np.where(y == label)[0]
plt.scatter(X[row_ix, 0], X[row_ix, 1], label=['cat', 'dog'])
plt.legend()
plt.show()
输出:
Plotting scatter distribution for binary classification ['cat', 'dog']
:
X, y = make_classification(n_samples=1000, n_features=2, n_redundant=0,
n_clusters_per_class=1, weights=[0.9], flip_y=0, random_state=1,)
counter = Counter(y)
for label, _ in counter.items():
row_ix = np.where(y == label)[0]
plt.scatter(X[row_ix, 0], X[row_ix, 1], label=label)
plt.legend()
plt.show()
output:
I wanted to replace 0
, 1
legend with cat
, dog
. Here I go:
for label, _ in counter.items():
row_ix = np.where(y == label)[0]
plt.scatter(X[row_ix, 0], X[row_ix, 1], label=['cat', 'dog'])
plt.legend()
plt.show()
output:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在循环的
的每次迭代中更改传奇标签的值,一种可能是使用
zip
You need to change the value of the legend's label in every iteration of the
for
loop, one possibility being the use ofzip