#5.绘制图形
#确定坐标轴范围
x1_min, x1_max=x[:,0].min(), x[:,0].max() #第0维特征的范围
x2_min, x2_max=x[:,1].min(), x[:,1].max() #第1维特征的范围
x1,x2=np.mgrid[x1_min:x1_max:200j, x2_min:x2_max:200j ] #生成网络采样点
grid_test=np.stack((x1.flat,x2.flat) ,axis=1) #测试点
#指定默认字体
matplotlib.rcParams['font.sans-serif']=['SimHei']
#设置颜色
cm_light=matplotlib.colors.ListedColormap(['#A0FFA0', '#FFA0A0'])
cm_dark=matplotlib.colors.ListedColormap(['r','b'] )
grid_hat = classifier.predict(grid_test) # 预测分类值
grid_hat = grid_hat.reshape(x1.shape) # 使之与输入的形状相同
plt.pcolormesh(x1, x2, grid_hat, cmap=cm_light) # 预测值的显示
plt.scatter(x[:, 0], x[:, 1], c=y[:,0], s=30,cmap=cm_dark,label='delivery parking spots') # 样本
plt.scatter(test_data[:,0],test_data[:,1], c=test_label[:,0],s=30,edgecolors='k', zorder=2,cmap=cm_dark) #圈中测试集样本点
plt.legend()
plt.xlabel('The speed before parking deceleration', fontproperties='The New Roman',fontsize=11)
plt.ylabel('Parking duration',fontproperties='The New Roman',fontsize=11)
plt.xlim(x1_min,x1_max)
plt.ylim(x2_min,x2_max)
plt.title('Identification of delivery points of domestic intercity trucking',fontproperties='The New Roman',fontsize=11,weight='bold')
plt.show()