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.
Multiple scatter plots can be graphed on the same plot using different x and y-axis data calling the function Matplotlib. pyplot. scatter() multiple times.
Using subplots() method, create a figure and a set of subplots. Plot [1, 2, 3, 4, 5] data points on the left Y-axis scales. Using twinx() method, create a twin of Axes with a shared X-axis but independent Y-axis, ax2. Plot [11, 12, 31, 41, 15] data points on the right Y-axis scale, with blue color.
Scatter Plot Color by Category using Matplotlib Matplotlib scatter has a parameter c which allows an array-like or a list of colors. The code below defines a colors dictionary to map your Continent colors to the plotting colors.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With