条件标记matplotlib

条件标记matplotlib

本文介绍了条件标记matplotlib的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我有 3 种由预测确定的点时,我绘制了高斯混合的结果.我为每个预测的簇设置了不同的颜色,现在我想要一个不同的标记而不是颜色.

I plot the result of a Gaussian Mixture when I have 3 type of points that are determinate by a prediction. I have a different color for each cluster predicted and now I would like to have a different marker instead of color.

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

它非常适合这样的颜色:

It works perfectly for colors like this:

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

But I can't do the same thing with different markers, it doesn't recognize a list of markers.

我怎样才能像颜色一样为每个簇 (0,1,2) 设置不同的标记?

How can I do to have a different marker for each cluster (0,1,2) like I have with colors?

推荐答案

将带有 plt.scatter 的那行改为这样:

Change the line with plt.scatter in it to this instead:

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

这篇关于条件标记matplotlib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 01:19