guogogo
guogogo

Reputation: 113

How do I alternate between different marker colors on matplotlib?

I am plotting a scatter graph using matplotlib in Python. Suppose I want each marker on the graph to be a different colour, so it alternates between a set of colours (e.g., the points go red, green, blue, red, green, blue, etc.), how can that be done? Looking at the documentation I'm guessing it has something to do with set_markerfacecoloralt()?

Upvotes: 1

Views: 2218

Answers (1)

xnx
xnx

Reputation: 25478

Simplest might be to use a scatter plot:

x = range(20)
y = 2*np.array(x)
pylab.scatter(x, y, color='rgb')

enter image description here

I think what @tcaswell is suggesting as an alternative in his comment is using plot three times with different colors on the appropriate slices:

pylab.plot(x[::3], y[::3], 'ro')
pylab.plot(x[1::3], y[1::3], 'go')
pylab.plot(x[2::3], y[2::3], 'bo')

Upvotes: 3

Related Questions