Search code examples
pythonmatplotlibscatter-plot

Adding an edge to scatter plot marker


I'm making a matplotlib plot in python. I have one marker that I am putting onto the plot using:

plt.scatter(x_position,y_position,c=z_position,cmap=cm.bwr,marker='x',s=500,linewidth=4)

As you can see, the color of the marker is a reflection of the z position.

My only problem is that sometimes the 'X' is not entirely distinct from the background (depending on the color of course), so I wanted to put a black outline around the 'X' marker.

I tried changing edgecolor, but this didn't seem to have an effect. I think this is because I have made the marker an 'X' and so there is no edge in the same way a regular circle scatter plot would have an edge?


Solution

  • You're using "x". That is an unfilled marker, like "+". If instead you use "X", it will be a filled marker, which can have a face- and an edgecolor.

    plt.scatter([1,2,3], [1,2,3], c=[1,2,3], s=1000, marker="X", 
                linewidth=1, edgecolor='k')
    
    plt.margins(1)
    plt.show()
    

    enter image description here