[英]plt.plot in python, annotate
如何获得 -0.1 和 0.1 之间的随机数以站在 plot 中的数据旁边? 这是我迄今为止尝试过的,但它不起作用......
grades = np.array([[-3,3,7],
[7,0,12],
[2,4,4],
[7,12,10]])
tasks = np.arange(1,grades.shape[1]+1)
n = np.random.uniform(-0.1,0.1,len(grades))
plt.figure()
for i in range(len(grades)):
plt.plot(tasks,grades[i,:],'b.')
for i, txt in enumerate(n):
plt.annotate(txt, (tasks[i],grades[i,:]))
plt.show()
尝试这个:
grades = np.array([[-3,3,7],
[7,0,12],
[2,4,4],
[7,12,10]])
tasks = np.arange(1,grades.shape[1]+1)
n = np.random.uniform(-0.1,0.1,len(grades))
for i in range(len(grades)):
plt.plot(tasks,grades[i,:],'g^')
for j, txt in enumerate(n):
plt.annotate(txt, (tasks[j-1],grades[i-1,j-1]))
plt.show()
#Edit:
#Can u try this For unique labelling:
import matplotlib.pyplot as plt
grades = np.array([[-3,3,7],
[7,0,12],
[2,4,4],
[7,12,10]])
tasks = np.arange(1,grades.shape[1]+1)
n = np.random.uniform(-0.1,0.1,len(grades))
tmp_list = []
for i in range(len(grades)):
plt.plot(tasks,grades[i,:],'g^')
for j, txt in enumerate(n):
if (tasks[j-1],grades[i-1,j-1]) not in tmp_list:
plt.annotate(txt, (tasks[j-1],grades[i-1,j-1]))
tmp_list.append((tasks[j-1],grades[i-1,j-1]),)
plt.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.