Python matplotlib scatter - 一个散布中的不同标记 [英] Python matplotlib scatter - different markers in one scatter

查看:28
本文介绍了Python matplotlib scatter - 一个散布中的不同标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示一些要点.这是我的代码:

I want to display some points. Here is my code:

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 给出错误.

So I have points in two different colours. But I also want to have two different markers. How can I do it? markers=col gives an error.

推荐答案

每个标记可以使用一个散点图.

You can use one scatter plot per marker.

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])

有关在单个散点图中使用多个标记的方法,请参见此答案.

For a way to use several markers in a single scatter plot, see this answer.

这篇关于Python matplotlib scatter - 一个散布中的不同标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆