Skip to content Skip to sidebar Skip to footer

Matplotlib Scatter Plot With Different Markers And Colors

I would like to make a plot with different markers and different colors according to the values of 2 external vectors. Here what I have tried: >>> s = [u'+', u'+', u'o']

Solution 1:

This works:

s = [u'+', u'+', u'o']
col = ['r','r','g']
x = np.array([1,2,3])
y = np.array([4,5,6])

for _s, c, _x, _y in zip(s, col, x, y):
    plt.scatter(_x, _y, marker=_s, c=c)

plt.xlim(0, 4)
plt.ylim(0, 8)

plt.show()

Rendering like this:

Plot of above code

Update

It seems you can have a variety of colors and have a single call to the scatter function: example. The multiple color feature is confirmed on the API but it doesn't read that you can specify an iterable for the marker kwarg. Your code works if you remove marker=s


Post a Comment for "Matplotlib Scatter Plot With Different Markers And Colors"