matplotlib scatterplot传说
这是一个常见问题的重复,但是我花了4个小时阅读回复,但我仍然无法理解它们,而我的代码会丢弃错误或返回意外结果。
此任务是如此简单,以至于它应该是一行代码。响应要么是代码墙,要么通过对每个类别进行单独的plt.scatter
来执行散点图,我不想这样做。
我如何为此创造传奇? X和Y数据用make_blobs
制造。
map = {0: 'red', 1:'green', 2:"blue"}
plt.scatter(X[:,0], X[:,1], c=[map[i] for i in y])
我想要的只是一个看起来像:
的传奇 (红点):0
(绿点):1
(蓝点):2
ffs
This is a repeat of a common question, but I've spent 4 hours reading responses and I still can't make sense of them and my code throws errors or returns unexpected results.
This task is so simple that it should be no more than a single line of code. Responses are either walls of code or they execute the scatter plot by doing a separate plt.scatter
call for each class, which I don't want to do.
How do I make a legend for this? X and y data was fabricated with make_blobs
.
map = {0: 'red', 1:'green', 2:"blue"}
plt.scatter(X[:,0], X[:,1], c=[map[i] for i in y])
All I want is a legend that looks like:
(red dot): 0
(green dot): 1
(blue dot): 2
ffs
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于无法使用完整的代码,我只是创建带有4个条目的虚拟数据,以演示如何使用您正在谈论的3种颜色创建散点图。这将根据您在
MAP
中输入的内容创建传奇。输出图
as the full code is not available, I am just creating dummy data with 4 entries to demonstrate how to create scatter plot with the 3 colors you are talking about. This will create the legend based on what you enter in
map
.Output graph