简体   繁体   English

带有标记数据的散点图,与 label 相关的标记

[英]Scatterplot with labeled data, marker in relation to label

i want to scatterplot a dataset with labeled data.我想用标记数据散点图数据集。 I want the several classes to be displayed in different marker styles.我希望将几个类显示在不同的标记 styles 中。 For Data generation i use the command:对于数据生成,我使用以下命令:

from sklearn.datasets import make_moons
X, y = make_moons(n_samples = 100, noise = 0.15)

After the data is generated:数据生成后:

X = array([[ 0.83193416,  0.67054039],
       [ 1.4017985 , -0.34708943],
       ...
       [ 1.02640652, -0.58107469],
       [-1.08443914,  0.51960219]])

y = array([0, 1, 1, 1, 0, ... 1, 0])

Equal sized Arrays have been generated, y is the label for data in X. Data labeled with 0 should be displayed as circles and data labeled with 1 should be displayed as triangles.已生成相同大小的 Arrays,y 是 X 中数据的 label。标记为 0 的数据应显示为圆形,标记为 1 的数据应显示为三角形。 Here is an example of what it has to look like: Example这是它的外观示例:示例

Thanks in advance.提前致谢。

Use y as a selector to filter rows of X. The x and y vectors for the plot are in the *columns of X, so we must transpose the data for the plot to make sense.使用y作为选择器来过滤 X 的行。plot 的 x 和 y 向量在 X 的 * 列中,因此我们必须转置 plot 的数据才有意义。 The splattering star * is used to split the columns into the first two arguments for plot().飞溅星*用于将列拆分为前两个 arguments 用于 plot()。 The colors and shapes are in the final parameters 'bo' and 'g^': colors 和形状在最终参数“bo”和“g^”中:

import matplotlib.pyplot as plt

plt.plot(*X[y==0].T, 'bo')  # blue circles (replace o -> s for squares like the picture)
plt.plot(*X[y==1].T, 'g^')  # green triangles
plt.axis('equal')
plt.grid('on')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM