small scatter plot markers in matplotlib are always black

后端 未结 4 460
后悔当初
后悔当初 2021-02-02 05:47

I\'m trying to use matplotlib to make a scatter plot with very small gray points. Because of the point density, the points need to be small. The problem is that the scatter()

4条回答
  •  执笔经年
    2021-02-02 06:24

    In response to zwol's question in comment - my reputation is not high enough to leave comments, so this will have to do: In the event that your colors come from a colormap (i.e., are from a "sequence of values to be mapped") you can use color = as demonstrated in the following:

    from matplotlib import pyplot
    
    x = [1,5,8,9,5]
    y = [4,2,4,7,9]
    numSides = [2,3,1,1,5]
    
    cmap = pyplot.cm.get_cmap("copper_r")
    
    min, max = min(numSides), max(numSides)
    for i in range(len(x)):
        if numSides[i] >= 2:
            cax = pyplot.scatter(x[i], y[i], marker = '+', s = 100, c = numSides[i], cmap = cmap)
            cax.set_clim(min, max)
        elif numSides[i] == 1:
            pyplot.scatter(x[i], y[i], marker = '.', s = 40, color = cmap(numSides[i]))
    
    fig = pyplot.gcf()
    fig.set_size_inches(8.4, 6)
    fig.savefig('figure_test.png', dpi = 200)
    pyplot.show()
    

提交回复
热议问题