-1

in zs[:,2] are numbers in my case such as from 1 to 5.

plt.scatter(zs[:,0], zs[:,1], c=zs[:,2], alpha=0.5)

What is the best way to map these numbers (from zs[:,2]) to specific colors?

malocho
  • 265
  • 3
  • 13
  • 1
    Does this answer your question? [How can I convert numbers to a color scale in matplotlib?](https://stackoverflow.com/questions/43009724/how-can-i-convert-numbers-to-a-color-scale-in-matplotlib) – DrBwts Apr 23 '20 at 10:13
  • 1
    add `cmap=plt.cm.jet` or another cmap to your scatter plot line. – BenT Apr 23 '20 at 21:02
  • @BenT I am not aware of cmaps, it is time to read about cmap, thank you! – malocho Apr 23 '20 at 21:06

1 Answers1

0

I did it in a similar way by means of panda lib (How can I convert numbers to a color scale in matplotlib?).

def col_map(x):
    print(x)
    if x == 0.0:
        return "green"
    if x == 1.0:
        return 'red'
    else:
        return 'blue'

df = pd.DataFrame({"x":zs[:,0],"y":zs[:,1],"c":[col_map(x) for x in zs[:,2].tolist()]})
plt.scatter(df.x, df.y, color=df.c)
malocho
  • 265
  • 3
  • 13