绘制标记和未标记的数据matplotlib

时间:2015-03-15 15:16:26

标签: python matplotlib

我有三个列表,分别是X,Y,Z

X = [[0.67910803031180977, 0.1443997264255876], [0.57, 0.87], [0.545, 0.854], [0.645, 0.1254], [0.645, 0.1354], [0.62, 0.83], [0.6945, 0.144], [0.9945, 0.45244], [0.235, 0.7754], [0.7, 0.85]]

Y = [0, 1, -1, -1, -1, 1, -1, -1, -1, 1]

Z = [0 1 1 0 0 1 0 1 1 1]

其中,

X is the dataset,
Y is labelset where 0 means "Normal", 1 means "LL" and -1 means "Unlabelled"
Z is outputset in which labels from Y is propagated to unlabelled labels.

现在,我试图绘制一个图形,其中一个子图包含数据集作为集群,相对于它所属的Y的每个标签,另一个子图显示关于Z的数据集。

我试过code from this example,但我无法做到。

请帮忙。

1 个答案:

答案 0 :(得分:1)

我猜你想要什么,但这里是一个用X和Z分别确定的颜色绘制X值的例子。它使用了很多默认行为 - 0到1之间的颜色值被绘制到默认颜色栏,即iirc - 但是你可以创建一个更复杂的函数并传递一个(rgb)或(rgba)值的列表代替。

import matplotlib.pyplot as plt
from numpy import array
X = array([[0.67910803031180977, 0.1443997264255876], [0.57, 0.87],
           [0.545, 0.854], [0.645, 0.1254], [0.645, 0.1354], [0.62, 0.83],
           [0.6945, 0.144], [0.9945, 0.45244], [0.235, 0.7754], [0.7, 0.85]])
Y = [0, 1, -1, -1, -1, 1, -1, -1, -1, 1]
Z = [0, 1, 1, 0, 0, 1, 0, 1, 1, 1]

# for readability mostly
Xx = X.T[0]
Xy = X.T[1]

fig = plt.figure()
ax1 = fig.add_subplot(121)
ax1.scatter(Xx, Xy, c=map(lambda c: 0.3 * c + 0.5, Y), s=50, alpha=0.75)
ax1.set_xlabel('Y labels')

ax2 = fig.add_subplot(122)
ax2.scatter(Xx, Xy, c=map(lambda c: 0.3 * c + 0.5, Z), s=50, alpha=0.75)
ax2.set_xlabel('Z labels')
plt.show()

enter image description here