分类图绘制
plt.figure(facecolor = 'w') #面板分成3类 cm_light = mpl.colors.ListedColormap(['#77E0A0', '#FF8080', '#A0A0FF']) #根据y的不同,填充颜色也不同 plt.pcolormesh(x1, x2, y_hat, cmap=cm_light) plt.scatter(x[:, 0], x[:, 1], c='y') patchs = [mpatches.Patch(color='#77E0A0', label = 'Iris-setosa'), mpatches.Patch(color='#FF8080', label = 'Itis-versicolor'), mpatches.Patch(color = '#A0A0FF', label = 'Iris-virginica')] plt.legend(handles=patchs, fancybox = True, framealpha=0.8) plt.show()