add an outline to matplotlib scatter markers in python

To add an outline to scatter markers in matplotlib, you can use the edgecolors parameter of the scatter function. Here's an example:

main.py
import matplotlib.pyplot as plt

# Create the data for the scatter plot
x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]

# Plot the scatter graph with an outline
plt.scatter(x, y, edgecolors='black')

# Show the plot
plt.show()
221 chars
12 lines

In this example, the edgecolors parameter is set to 'black', which creates a black outline for the scatter marker. You can customize the color of the outline by changing the value passed to edgecolors to any valid matplotlib color specification.

Note that the edgecolors parameter can also be a sequence of colors, allowing you to assign different colors to different markers in a scatter plot.

You can experiment with other parameters like facecolors, linewidths, and alpha to further customize your scatter plot.

Hope this helps!

gistlibby LogSnag