1、scatter函数原型

2、其中散点的形状参数marker如下:

3、其中颜色参数c如下:

4、基本的使用方法如下:
- import numpy as np  
 
- import matplotlib.pyplot as plt  
 
- x = np.arange(1,10)  
 
- y = x  
 
- fig = plt.figure()  
 
- ax1 = fig.add_subplot(111)  
 
- ax1.set_title(‘Scatter Plot‘)  
 
- plt.xlabel(‘X‘)  
 
- plt.ylabel(‘Y‘)  
 
- ax1.scatter(x,y,c = ‘r‘,marker = ‘o‘)  
 
- plt.legend(‘x1‘)  
 
- plt.show()  
 
 
结果如下:

5、当scatter后面参数中数组的使用方法,如s,当s是同x大小的数组,表示x中的每个点对应s中一个大小,其他如c,等用法一样,如下:
(1)、不同大小
- import numpy as np  
 
- import matplotlib.pyplot as plt  
 
- x = np.arange(1,10)  
 
- y = x  
 
- fig = plt.figure()  
 
- ax1 = fig.add_subplot(111)  
 
- ax1.set_title(‘Scatter Plot‘)  
 
- plt.xlabel(‘X‘)  
 
- plt.ylabel(‘Y‘)  
 
- sValue = x*10  
 
- ax1.scatter(x,y,s=sValue,c=‘r‘,marker=‘x‘)  
 
- plt.legend(‘x1‘)  
 
- plt.show()  
 
 

(2)、不同颜色
- import numpy as np  
 
- import matplotlib.pyplot as plt  
 
- x = np.arange(1,10)  
 
- y = x  
 
- fig = plt.figure()  
 
- ax1 = fig.add_subplot(111)  
 
- ax1.set_title(‘Scatter Plot‘)  
 
- plt.xlabel(‘X‘)  
 
- plt.ylabel(‘Y‘)  
 
- cValue = [‘r‘,‘y‘,‘g‘,‘b‘,‘r‘,‘y‘,‘g‘,‘b‘,‘r‘]  
 
- ax1.scatter(x,y,c=cValue,marker=‘s‘)  
 
- plt.legend(‘x1‘)  
 
- plt.show()  
 
 
结果:

(3)、线宽linewidths
- import numpy as np  
 
- import matplotlib.pyplot as plt  
 
- x = np.arange(1,10)  
 
- y = x  
 
- fig = plt.figure()  
 
- ax1 = fig.add_subplot(111)  
 
- ax1.set_title(‘Scatter Plot‘)  
 
- plt.xlabel(‘X‘)  
 
- plt.ylabel(‘Y‘)  
 
- lValue = x  
 
- ax1.scatter(x,y,c=‘r‘,s= 100,linewidths=lValue,marker=‘o‘)  
 
- plt.legend(‘x1‘)  
 
- plt.show()  
 
 

 
                     注:  这就是scatter基本的用法。