2016-11-10 4 views
0

Ich möchte Schleife und Plot-Datei InformationenDrucken von Etiketten in einer Schleife

-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 

, die mat0 geladen wird Dies ist, was ich bisher:

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() 

Das Problem ist, dass ich tun Etiketten werden überhaupt nicht gedruckt. Ich bekomme auch keinen Fehler. Was vermisse ich?

+0

'% s' steht für Strings. Sind Sie sicher, dass Sie keinen Fehler bekommen? –

+0

@ cricket_007 Aye, keine Fehler (?) Aber es wird auch nichts gedruckt – Manolete

+0

Was ist 'mat0'? Kannst du bitte [mcve] machen? –

Antwort

1

Sie müssen das Objekt legend aufrufen. Sie tun dies, indem Sie plt.legend() anrufen.

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() 
Verwandte Themen