2

I'm trying to figure out why this piece of my code won't work. I'm trying to set "mark" as a variable so that it can use different markers depending on what a certain column reads. Everything else in the plot works fine, but when I add this part:

mark = ["s" if t == "M" else "o" for t in z]

plt.scatter(x2[yesGEM],y1[yesGEM],c="green",label='Observed (GemN)', marker=mark)

I get:

ValueError: Unrecognized marker style ['o', 's', 'o', 'o', 'o', 's', 'o', 'o',......'o']

Any idea why this is?

uhurulol
  • 345
  • 5
  • 15
  • 1
    http://stackoverflow.com/questions/26490817/matplotlib-scatter-plot-with-different-markers-and-colors – furas Feb 01 '16 at 23:45

1 Answers1

0

I don't think you can set marker as an iterable when you call scatter (see the docs), so you'd have to split your data into two groups and scatter them separately: e.g. (assuming x2 and y1 correspond to the values in z):

data_s = []
data_o = []
for i,t in enumerate(z):
    if t == 'M':
         data_s.append(x2[i], y1[i])
    else:
         data_o.append(x2[i], y1[i])

plt.scatter(*zip(*data_s), marker='s', c='g')
plt.scatter(*zip(*data_o), marker='o', c='g')
xnx
  • 24,509
  • 11
  • 70
  • 109