plt.scatter(X_pca[:, 0], X_pca[:, 1], marker='o', s=100, c=kpredictions, alpha=1, cmap="winter", label=label9) plt.scatter(X_pca[:, 0], X_pca[:, 1], marker='o', s=100, c=kpredictions, alpha=1, cmap="gnuplot2", label=label5) plt.scatter(X_pca[:, 0], X_pca[:, 1], marker='o', s=100, c=kpredictions, alpha=1, cmap="hot", label=label6) plt.scatter(X_pca[:, 0], X_pca[:, 1], marker='o', s=100, c=kpredictions, alpha=1, cmap="autumn", label=label7) plt.scatter(X_pca[:, 0], X_pca[:, 1], marker='o', s=100, c=kpredictions, alpha=1, cmap="terrain", label=label8) plt.scatter(X_pca[:, 0], X_pca[:, 1], marker='o', s=100, c=kpredictions, alpha=1, cmap="Oranges", label=label1) plt.scatter(X_pca[:, 0], X_pca[:, 1], marker='o', s=100, c=kpredictions, alpha=1, cmap="tab20b", label=label2) plt.scatter(X_pca[:, 0], X_pca[:, 1], marker='o', s=100, c=kpredictions, alpha=1, cmap="cool", label=label4) plt.scatter(X_pca[:, 0], X_pca[:, 1], marker='o', s=100, c=kpredictions, alpha=1, cmap="rainbow", label=label3)
时间: 2024-04-08 13:33:02 浏览: 154
python matplotlib:plt.scatter() 大小和颜色参数详解
5星 · 资源好评率100%
您想要绘制多个散点图,每个散点图使用不同的颜色映射。您可以按照以下代码进行绘制:
```python
plt.scatter(X_pca[:, 0], X_pca[:, 1], marker='o', s=100, c=kpredictions, alpha=1, cmap="winter", label=label9)
plt.scatter(X_pca[:, 0], X_pca[:, 1], marker='o', s=100, c=kpredictions, alpha=1, cmap="gnuplot2", label=label5)
plt.scatter(X_pca[:, 0], X_pca[:, 1], marker='o', s=100, c=kpredictions, alpha=1, cmap="hot", label=label6)
plt.scatter(X_pca[:, 0], X_pca[:, 1], marker='o', s=100, c=kpredictions, alpha=1, cmap="autumn", label=label7)
plt.scatter(X_pca[:, 0], X_pca[:, 1], marker='o', s=100, c=kpredictions, alpha=1, cmap="terrain", label=label8)
plt.scatter(X_pca[:, 0], X_pca[:, 1], marker='o', s=100, c=kpredictions, alpha=1, cmap="Oranges", label=label1)
plt.scatter(X_pca[:, 0], X_pca[:, 1], marker='o', s=100, c=kpredictions, alpha=1, cmap="tab20b", label=label2)
plt.scatter(X_pca[:, 0], X_pca[:, 1], marker='o', s=100, c=kpredictions, alpha=1, cmap="cool", label=label4)
plt.scatter(X_pca[:, 0], X_pca[:, 1], marker='o', s=100, c=kpredictions, alpha=1, cmap="rainbow", label=label3)
plt.legend()
plt.show()
```
这段代码会按照您指定的不同颜色映射绘制多个散点图,并在图例中显示相应的标签。
阅读全文