[英]Label data when doing a scatter plot in python
I want to label every dot I plot in python, and I didn't find a proper way to do it. 我想标记我在python中绘制的每个点,我没有找到合适的方法来做到这一点。
Assuming I have two lists of n
elements called a
and b
, I print them this way : 假设我有两个名为
a
和b
的n
元素列表,我会这样打印:
plt.figure()
plt.grid()
plt.plot(a , b , 'bo')
plt.show()
I want to label every point with "Variable k" with k
ranging from 1
to n
obviously. 我想用“变量k”标记每个点,其中
k
显然在1
到n
。 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()
More infos : Matplotlib: How to put individual tags for a scatter plot 更多信息: Matplotlib:如何为散点图放置单个标签
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.