如何将这个特定图例中的0和1值分别更改为“否”和“是”?
import matplotlib.pyplot as plt
import numpy as np
plt.contourf(x1, x2, regr.predict(np.array([x1.ravel(), x2.ravel()]).T).reshape(x1.shape), alpha=0.75, cmap = ListedColormap(('red','green')))
for i, j in enumerate(np.unique(y_set)):
plt.scatter(x_set[y_set == j, 0], x_set[y_set == j,1], c = ListedColormap(('black','white'))(i),label=j)
plt.legend()
这是您的建议:仅需要删除的标签plt.scatter(..., label=['No','Yes'])
。
import matplotlib.pyplot as plt
import numpy as np
plt.contourf(x1, x2, regr.predict(np.array([x1.ravel(), x2.ravel()]).T).reshape(x1.shape), alpha=0.75, cmap = ListedColormap(('red','green')))
for i, j in enumerate(np.unique(y_set)):
plt.scatter(x_set[y_set == j, 0], x_set[y_set == j,1], c = ListedColormap(('black','white'))(i),label=['No','Yes'])
plt.legend()
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句