Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the border color of the dots in matplotlib's scatterplots?

Is it possible to set the color of the borders of the dots that are generated via the Axes.scatter or is it always black?

thanks!

like image 860
fstab Avatar asked Nov 21 '13 16:11

fstab


People also ask

Is it possible to choose different color for each dots in the scatter plot?

Output: Now to change the colors of a scatterplot using plot(), simply select the column on basis of which different colors should be assigned to various points.

How do you specify colors in a scatter plot?

scatter( x , y , sz , c ) specifies the circle colors. You can specify one color for all the circles, or you can vary the color. For example, you can plot all red circles by specifying c as "red" .

How do you change the dot color on a scatter plot in Python?

To set color for markers in Scatter Plot in Matplotlib, pass required colors for markers as list, to c parameter of scatter() function, where each color is applied to respective data point. We can specify the color in Hex format, or matplotlib inbuilt color strings, or an integer.

How do I highlight points in Matplotlib?

Matplotlib has a function named annotate() to add text in a specific location in a plot. We need to specify annotate() function the text we want to annotate the plot with and the x and y co-ordinates for the location of the text.


1 Answers

If you want to make all the edges the same color:

ax.scatter(...., edgecolor=EC)

where EC is a color. If you want to surpress the edge (so it looks like the edge color matches the face color) use

ax.scatter(..., linewidths=0)

If you want to have the edges be a different color than the face and each marker have it's own color it looks like you have to do the mapping your self:

my_cmap = cm.get_cmap('jet')
my_norm = matplotlib.colors.Normalize()
ec_data = rand(15)
my_normed_data = my_norm(ec_data)
ec_colors = my_cmap(my_normed_data) # a Nx4 array of rgba value
ax.scatter(rand(15), rand(15), s=500, c=rand(15), edgecolors=ec_colors, linewidth=3)

enter image description here

like image 88
tacaswell Avatar answered Oct 08 '22 22:10

tacaswell