matplotlib scatter plot with different markers and colors

前端 未结 1 1105
-上瘾入骨i
-上瘾入骨i 2020-12-11 02:20

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:

>&         


        
相关标签:
1条回答
  • 2020-12-11 03:01

    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

    0 讨论(0)
提交回复
热议问题