I want to have a scatter plot with colormap for edgecolors but no facecolors.
When I use facecolor='None'
, it does not work.
import numpy as np
import matplotlib.pyplot as plt
N = 50
x = np.random.rand(N)
y = np.random.rand(N)
colors = np.random.rand(N)
area = np.pi * (15 * np.random.rand(N))**2 # 0 to 15 point radii
plt.scatter(x, y, s=area,c=colors,facecolors='None',cmap="gist_rainbow", alpha=0.5)
plt.show()
Any solution?
Matplotlib scatter plot color label To create a scatter plot, we use the scatter() method. To add a legend to a plot, we use the legend() method. To set the color of the legend, we pass facecolor parameter to the method.
Just use the marker argument of the plot() function to custom the shape of the data points.
The primary difference of plt. scatter from plt. plot is that it can be used to create scatter plots where the properties of each individual point (size, face color, edge color, etc.) can be individually controlled or mapped to data.
To set an edge color of the scatter markers, use the edgecolor parameter with the scatter () method. Here we pass the parameter edgecolor, color to the scatter () function and set its value to black and lime respectively. Here we’ll see an example, where we set the different edgecolors for each scatter marker. Import library matplotlib.pyplot.
The Matplotlib module has a number of available colormaps. A colormap is like a list of colors, where each color has a value that ranges from 0 to 100. This colormap is called 'viridis' and as you can see it ranges from 0, which is a purple color, and up to 100, which is a yellow color.
You can set your own color for each scatter plot with the color or the c argument: You can even set a specific color for each dot by using an array of colors as value for the c argument: Note: You cannot use the color argument for this, only the c argument. The Matplotlib module has a number of available colormaps.
Import library matplotlib.pyplot. Next, define x and y axes data points. Then create list of colors. To plot a scatter graph, use scatter () function. To set the different edgecolor for each scatter pass edgecolor parameter and set its value to given list of colors. We’ll see an example, where we set a different color for each scatter point.
The c
argument will affect facecolor and edgecolor simultaneouly, the arguments facecolor
and edgecolor
are hence ignored.
A solution would be not to use the c
argument together with a colormap, but instead use facecolors
and edgecolors
alone. In this case facecolors
can be set to "None"
and edgecolors
can be given a list of colors to use.
To create this list, the same colormap can be applied.
c = plt.cm.gist_rainbow(colors)
plt.scatter(x, y, s=area,facecolors="None", edgecolors=c, lw=1,alpha=0.5)
A complete example:
import numpy as np
import matplotlib.pyplot as plt
N = 50
x = np.random.rand(N)
y = np.random.rand(N)
colors = np.random.rand(N)
area = np.pi * (15 * np.random.rand(N))**2 # 0 to 15 point radii
c = plt.cm.gist_rainbow(colors)
plt.scatter(x, y, s=area,facecolors="None", edgecolors=c, lw=2,alpha=0.5)
plt.show()
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