plt.scatter() 散点图多种类添加图例问题

问题描述: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

https://matplotlib.org/2.0.2/users/legend_guide.html

https://ask.csdn.net/questions/7621665

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值