问题描述:tsne 二维散点图多类别添加图例
理论知识
plt.legend() 参数详见链接 plt.legend()参数详情
这里只进行多图例演示
N = 45
x, y = np.random.rand(2, N)
fig, ax = plt.subplots()
x1, y1= x[ : 10], y[ : 10]
x2, y2 = x[10 : 20], y[10 : 20]
x3, y3 = x[20 : 30], y[20 : 30]
x4, y4 = x[30 : 40], y[30 : 40]
x5, y5 = x[40 : 45], y[40 : 45]
p1 = ax.scatter(x1, y1, c='red', marker = '.' )
p2 = ax.scatter(x2, y2, c= 'peru', marker = 'o')
p3 = ax.scatter(x3, y3, c='gold', marker = 'D' )
p4 = ax.scatter(x4, y4, c='green', marker = 'h')
p5 = ax.scatter(x5, y5, c='blue', marker = 'v')
plt.legend([p1, p2, p3, p4, p5], ['aa-.', 'bb-o', 'cc-D', 'dd-h', 'ee-v'], loc = 0)
效果图:
参考链接:
https://blog.csdn.net/mighty13/article/details/113820798