python matplotlib scatter - 在一个分散的不同标记
问题描述:
我想显示一些点。这里是我的代码:python matplotlib scatter - 在一个分散的不同标记
plt.scatter(y[:,0],y[:,1],c=col)
plt.show()
正如col
我:
Col: [1 1 0 1 1 1 1 0 0 0 1 0 0 0 0 0 0 1 1 1 0 0 1 1 0 0 0 0 1 1 0 1 1 0 0 0 0
0 0 0 0 0 0 0 1 1 0 1 1 0 1 0 0 1 0 1 1 0 1 0 1 0 0 1 1 1 1 1 1 1 1 1 0 0
1 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1 0 1 0 0 1 1 0 1 0 0]
所以,我有两种不同颜色的点。但我也想要两个不同的标记。我该怎么做? markers=col
提供了一个错误。
答
您需要为每个标记使用一个散点图。
markers = ["s","o"]
for i, c in enumerate(np.unique(col)):
plt.scatter(y[:,0][col==c],y[:,1][col==c],c=col[col==c], marker=markers[i])
答
Matplotlib在一次调用中不支持不同的标记来分散。您必须使用两个不同的电话scatter
;例如:
plt.scatter(y[col == 0, 0], y[col == 0, 1], marker='o')
plt.scatter(y[col == 1, 0], y[col == 1, 1], marker='+')
它的工作原理,谢谢! –