簡體   English   中英

plt.plot 在 python 中,注釋

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM