5

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:

enter image description here

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

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

Mad Physicist
  • 107,652
  • 25
  • 181
  • 264
Elysire
  • 693
  • 10
  • 23
  • 1
    You have to loop through them. See here http://stackoverflow.com/questions/41078331/matplotlib-read-marker-direction-from-a-file/41078504#41078504 – p-robot Dec 12 '16 at 11:35

2 Answers2

3

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)  
p-robot
  • 4,652
  • 2
  • 29
  • 38
1

Assuming that resultGM is an array of integer labels. If it's not, turn it into one. You should have exactly one call to scatter for each cluster, not one call per data point as the other answer suggests:

colors = ['pink', 'skyblue', 'lightgreen', ...]
markers = ['c', 'o', 'D', ...]

for i in range(resultGM.max()):
    mask = (resultGM == i)
    ax.scatter(data[mask, 0], data[mask, 1], alpha=0.8, c=colors[i], marker=markers[i])  
Mad Physicist
  • 107,652
  • 25
  • 181
  • 264