在python中进行散点图时标记数据 [英] Label data when doing a scatter plot in python

查看:2129
本文介绍了在python中进行散点图时标记数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想标记我在python中绘制的每个点,但是我没有找到正确的方法.

I want to label every dot I plot in python, and I didn't find a proper way to do it.

假设我有两个名为abn元素列表,我以这种方式打印它们:

Assuming I have two lists of n elements called a and b, I print them this way :

    plt.figure()
    plt.grid()
    plt.plot(a , b , 'bo')
    plt.show()

我想用k显然是从1n的变量k"标记每个点. 谢谢您的时间

I want to label every point with "Variable k" with k ranging from 1 to n obviously. Thanks for your time

推荐答案

这是我发现的最好方法:

Here is the best way of doing it I found :

plt.figure()
plt.scatter(a,b)
labels = ['Variable {0}'.format(i+1) for i in range(n)]
for i in range (0,n):
    xy=(a[i],b[i])
    plt.annotate(labels[i],xy)
plt.plot()

更多信息: Matplotlib:如何放置个人散点图的标签

这篇关于在python中进行散点图时标记数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆