Common usage of plt.scatter() function


Recently, I came across the plt.scatter() function when I was coding the small Archie code. I found it very useful, so I summarized it and shared it with my friends. Refer
to the original blogger: link: link .

1. Definition of scatter() function

matplotlib.pyplot.scatter(x, y, s=None, c=None, marker=None, cmap=None, norm=None, vmin=None, vmax=None, alpha=None, linewidths=None, verts=None, edgecolors=None, *, data=None, **kwargs)

Eigenvalues effect
x,y Plot the data points (X,Y) of the scatterplot
s A parameter used to adjust the size of the marker
c Indicates the color. The default is blue'b', which represents the color of the mark, or it can be a character representing the color, or a sequence of length n representing the color, etc. such as'b'=blue,'y'=yellow, 'k'=black etc.
marker Indicates the style of the tag, the default is 'o'.
cmap Colormap entity or the name of a colormap, cmap is only used when c is an array of floats. If there is no declaration, it is image.cmap
norm The Normalize entity is used to convert the brightness of the data between 0-1, and it is only used when c is an array of floating point numbers. If not declared, it defaults to colors.Normalize.
vmin, vmax Real number, ignored when norm is present. Used to normalize brightness data.
alpha Real number, between 0-1. Used to adjust the transparency of the marker, the default is 1
linewidths That is, the length of the marker point.

2. Usage of scatter() function

import numpy as np
import matplotlib.pyplot as plt

plt.rcParams['font.sans-serif']=['simhei']  #标题字体
plt.title('scatter测试图')     #图片标题
np.random.seed(1) #使用相同的seed()值,则每次生成的随即数都相同
x = np.random.rand(5)
y = np.random.rand(5) #随机生成5个x,y的值

colors = np.array([1,0,0,1,1]) #颜色标签列表
area = 20*10    #可以自行调节大小
lines=np.zeros(10)+5
plt.scatter(x, y, s=area,c=colors, alpha=0.5,linewidths=lines)
plt.show()

Output
output:
picture:insert image description here

You can also change the style of the market markup

import numpy as np
import matplotlib.pyplot as plt

plt.rcParams['font.sans-serif']=['simhei']  #标题字体
plt.title('scatter测试图')     #图片标题
np.random.seed(1)   #使用相同的seed()值,则每次生成的随即数都相同
x = np.random.rand(5)
y = np.random.rand(5)

colors = np.array([1,0,0,1,1])
area = 20*10
lines=np.zeros(10)+5
plt.scatter(x, y, s=area,c=colors,marker='x')
plt.show()

insert image description here

Guess you like

Origin blog.csdn.net/Wwwwwww527/article/details/109860960
Recommended