在 matplotlib 中,我使用循环来绘制图形,每一步仅绘制一个具有特定颜色 C[index] 的数据点(X[index],Y[index]),以便为每个数据点分配颜色观点。总的来说,我用 8 种颜色来表示我的数据点,所以我希望我可以用这 8 种颜色来做一个图例,每种颜色代表一个含义。
这是我的代码。感谢帮助。:)
for index in range(0,len(X)):
plt.plot(X[index],Y1[index], marker = 'o', markersize = 10, color = C[index])
plt.xlabel("the percentage of students' credit hours found in instructor data", fontsize=14, color ="blue")
plt.ylabel("total number of writing assinments", fontsize=14, color="blue")
plt.axis([0, 100, 0, max(Y1)])
plt.show()