python - 条件标记 matplotlib

标签 python matplotlib markers

当我有 3 种由预测确定的点时,我绘制了高斯混合的结果。我对每个预测的集群都有不同的颜色,现在我想要一个不同的标记而不是颜色。

colors=['pink' if i==0 else 'skyblue' if i==1 else 'lightgreen' for i in resultGM]
markers=['c' if i==0 else 'o' if i==1 else 'D' for i in resultGM]
ax=plt.gca()
ax.scatter(datas[:, 0], datas[:, 1], alpha=0.8, c=colors, marker=markers)   
plt.title("Calling " + name_snp)
plt.xlabel('LogRatio')
plt.ylabel('Strength')
plt.show()

它非常适合这样的颜色:

enter image description here

但是我不能用不同的标记做同样的事情,它不能识别标记列表。

如何为每个集群设置不同的标记 (0,1,2)就像我有颜色?

最佳答案

plt.scatter 换行改为:

for x, y, c, m in zip(datas[:,0], datas[:,1], colors, markers)
    ax.scatter(x, y, alpha=0.8, c=c,marker=m)  

关于python - 条件标记 matplotlib,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41099887/

相关文章:

python - Camelot python;OSError : exception: access violation writing 0x00000080

python - Matplotlib 在绘图时将最后一个点连接到第一个点

javascript - Google map 商店定位器和搜索

python - 使用matplotlib制作动画并保存视频文件

python - 如何将自定义注释从数据框添加到堆积条形图?

每个句柄具有不同数量和颜色标记的 Matplotlib 图例

z-index - 更改 openlayers 中标记的 z 索引

python - 为什么 Python 字符串连接适用于俄语文本,但 string.format() 不起作用

python - PIL.Image.open() IOError : cannot identify image file

python - gcloud 函数使用 os.subprocess : [WinError 2] The system cannot find the file specified 进行部署