Python中的散点图

发布于 2025-02-11 10:22:01 字数 149 浏览 0 评论 0原文

我有一个尺寸为100x2的向量x,以及向量y = {1,-1}的相应二进制标签,长度为100。数据点对应于标签,例如红色为-1,对于给定数据点,黄色为1。

我一直在研究matplotlib和FCN散点,但是它仅接受一个特征向量及其标签。

我将感谢任何帮助。

I have a vector X of size 100x2 and the corresponding binary labels in a vector y ={1, -1} of length 100. I would like to plot the scattered data with s.t. I get the features on the axis and the color of the data point corresponds to a label e.g. red is -1, yellow is 1 for a given data point.

I've been looking into matplotlib and the fcn scatter however it accepts only a single feature vector and its label.

I would be grateful for any help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤单情人 2025-02-18 10:22:02

您可以使用seaborn(或Matplotlib)轻松执行此操作。以下是代码。

  1. 我正在创建一个大小为100x2并将其称为X的随机阵列。我正在创建一个0s和1s 100x1的随机阵列,并称其为y
>> import numpy as np
>> X = np.random.randint(100, size=(100, 2))
>> Y = np.random.choice([0, 1], size=(100))
>> X
   array([[11, 47],
       [23,  2],
       [91, 14],
       [65, 32],
       [81, 78],
       ....
>> Y
   array([0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1,
       0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0,
       1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1,
       0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1,
       1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1])

使用Seaborn Scactplot

import seaborn as sns
sns.scatterplot(x=X[:,0], y=X[:,1], hue=Y)

输出SNS STACTPLOT

You can do this easily using seaborn (or matplotlib as well). Below is the code.

  1. I am creating a random array of size 100x2 and calling it X. I am creating a random array of 0s and 1s of size 100x1 and calling it Y
>> import numpy as np
>> X = np.random.randint(100, size=(100, 2))
>> Y = np.random.choice([0, 1], size=(100))
>> X
   array([[11, 47],
       [23,  2],
       [91, 14],
       [65, 32],
       [81, 78],
       ....
>> Y
   array([0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1,
       0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0,
       1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1,
       0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1,
       1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1])

Use Seaborn scatterplot

import seaborn as sns
sns.scatterplot(x=X[:,0], y=X[:,1], hue=Y)

Output sns scatterplot

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文