打印标签

打印标签

问题描述:

我想这是加载到mat0 环和打印文件信息打印标签

-1 1 0.732313 
-1 2 1.33585 
-1 4 1.05306 
-1 8 1.56261 
-1 16 1.90336 
-1 32 1.71105 
-1 64 1.8319 

这是我到目前为止有:

mat0 = genfromtxt("mydata") 
fig1 = plt.figure() 
ax = fig1.add_subplot(111) 
mybel =-1 
count =0 
while (count < 60): 
    i=count 
    j= i+6          
    plt.plot(mat0[i:j,1], mat0[i:j,2],label="Size %s"%mybel) 
    count = count + 7 
    mybel = mybel +1 

plt.show() 

的问题是,我做的根本不打印标签。我也没有得到任何错误。我错过了什么?

+0

'%s'用于字符串。你确定你没有错误吗? –

+0

@ cricket_007是的,没有错误(?),但它不打印任何东西 – Manolete

+0

什么是'mat0'?你可以做一个[mcve]吗? –

您需要致电legend对象。您可以致电plt.legend()

mat0 = genfromtxt("mydata") 
fig1 = plt.figure() 
ax = fig1.add_subplot(111) 
mybel =-1 
count =0 
while (count < 60): 
    i=count 
    j= i+6          
    plt.plot(mat0[i:j,1], mat0[i:j,2],label="Size %s"%mybel) 
    count = count + 7 
    mybel = mybel +1 
plt.legend() 
plt.show()