【发布时间】:2021-07-14 09:21:20
【问题描述】:
我想在图例中添加我的标签,从 0 到 7,但我不想在我的代码中添加一个 for 循环并逐步更正每个标签,我的代码就是这样,
fig, ax = plt.subplots()
ax.set_title('Clusters by OPTICS in 2D space after PCA')
ax.set_xlabel('First Component')
ax.set_ylabel('Second Component')
points = ax.scatter(
pca_2_spec[:,0],
pca_2_spec[:,1],
s = 7,
marker='o',
c = pred_pca_2_spec,
cmap= 'rainbow')
ax.legend(*points.legend_elements(), title = 'cluster')
plt.show()
【问题讨论】:
标签: python-3.x matplotlib