Reputation: 131
I wish to plot a scatter plot with no facecolors but with different edgecolors. In other words, colorful circles.
I thought I could easily found solution in matplotlib gallery but surprisingly I couldn't. Parameter "edgecolors" does not accept array as values. And manipulate parameter 'c' won't help with edgecolors but facecolors.
Here is a link that I thought would be the solution:
https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.scatter.html
The demo picture at the end of the page seems to have colorful edgecolors! Then I download the script and run it:
The edge is still black.
I am now doing my plot other ways. (since this is not a big matter. This is only a question of interest.) I just wonder how did the demo get the colorful edges.
Upvotes: 11
Views: 47213
Reputation: 404
As others have said the way that the demo script got the colourful edges is that matplotlib 2.0 automatically sets the edge colour of the points in the scatter plot to the provided colour argument.
If, however, you want to recreate the results of the demo script without updating to mpl 2.0 (though I recommend it) you only need to add an additional keyword parameter to the scatter line as follows
plt.scatter(x, y, s=area, c=colors, alpha=0.5, edgecolors=colors)
And for the sake of completeness you can implement the colourful circle idea that you originally had by faking it. You only need to change the internal colour to white, i.e.
plt.scatter(x, y, s=area, c='w', alpha=0.5, edgecolors=colors)
Additionally, you can't use a single float to define the colour for edgecolors as they are doing for the 'c' argument in the demo script so you either need to supply an array of length N that are all specified colours, e.g. ['r', 'g', 'b'], or replace the definition of the colours with
colors = np.random.random((N, p))
where p is either 3 or 4 depending if you want RGB or RGBA colours in the plot. This should produce something like the following plot
Upvotes: 9