散点图
from numpy import * import matplotlib.pyplot as plt dataSet = array([[ 1. , 2.1],[ 2. , 1.1],[ 1.3, 1. ],[ 1. , 1. ],[ 2. , 1. ]]) x=dataSet[:,0] y=dataSet[:,1] plt.scatter(x,y,s=30,c='y') plt.xlabel('x1') plt.ylabel('x2') plt.show()
数据集是矩阵时:
from numpy import * import matplotlib.pyplot as plt dataSet = mat([[ 1. , 2.1],[ 2. , 1.1],[ 1.3, 1. ],[ 1. , 1. ],[ 2. , 1. ]]) x=dataSet[:,0].flatten().A[0] #降维 y=dataSet[:,1].flatten().A[0] plt.scatter(x,y,s=30,c='y') plt.xlabel('x1') plt.ylabel('x2') plt.show()