0
h = .02     
x_min, x_max = X[:, 0].min() - 1, X[:, 0].max() + 1
y_min, y_max = X[:, 1].min() - 1, X[:, 1].max() + 1
xx, yy = numpy.meshgrid(numpy.arange(x_min, x_max, h),
                        numpy.arange(y_min, y_max, h))
Y = linsvc.predict(numpy.c_[xx.ravel(), yy.ravel()])

# Mettre le résultat dans un tracé couleur
colors = numpy.array([x for x in "bgrcmyk"])
Y = Y.reshape(xx.shape)
pyplot.contourf(xx, yy, Y, cmap=pyplot.cm.Paired, alpha=0.8)
pyplot.scatter(X[:, 0], X[:, 1], cmap=pyplot.cm.Paired,\
  color=colors[R].tolist())
pyplot.xlim(xx.min(), xx.max())
pyplot.ylim(yy.min(), yy.max())
pyplot.show()

This code create the following plot :

enter image description here

How can I add a legend for the blue dots and the green dots?

David
  • 393
  • 3
  • 4
  • 11
  • Probably separate the blue and green dots in two `pyplot.scatter` commands with `label=`. – Quang Hoang Oct 08 '20 at 14:40
  • Does this answer your question? [Adding a legend to PyPlot in Matplotlib in the simplest manner possible](https://stackoverflow.com/questions/19125722/adding-a-legend-to-pyplot-in-matplotlib-in-the-simplest-manner-possible) – J'e Oct 08 '20 at 14:41

0 Answers0