2017-03-06 3 views
-1

Ich habe einen Datenrahmen genannt df:Python mehrere Parzellen auf denselben Parzellen

IdDeviceType . NameDevice IdBox value hour 
    471   Heater  4  0.3  3 
    486   Thermo  5  0.6  14 
    492   Censor  8  0.8  22 

Ich möchte die Heizung und die thermo plotten Mittelwert von Stunde gruppiert pro Wohnung (eine Wohnung ist eine IdBox Nummer).

def my_plot(df2, x1, x2, idbox): 
    dev_id1 = df2['NameDevice'].isin(x1) 
    df2 = df2[dev_id] 
    print (set(df2.value.values)) 
    vals1 = [df2[df2['IdBox'] == idb].groupby('hour')['value'].mean() 
     for idb in idbox] 
    for val1 in vals1: 
    plot1 = plt.plot(val1.values) 

    dev_id2 = df2['NameDevice'].isin(x2) 
    df2 = df2[dev_id] 
    print (set(df2.value.values)) 
    vals2 = [df2[df2['IdBox'] == idb].groupby('hour')['value'].mean() 
     for idb in idboxe] 
    for val2 in vals2: 
    plot2 = plt.plot(vals2.values) 

plt.xlabel('hour') 
plt.ylabel('mean Value') 
plt.show() 

my_plot(df, ['Heater'],['Thermo'], [7]) 
+0

'plt.show()' muss sein außerhalb der for-Schleife. Wenn dies nicht der Fall ist, müssen Sie [mcve] angeben. – ImportanceOfBeingErnest

+0

Ich habe es geändert, um es klar zu machen – cloclo

+1

Dies ist ** nicht ** ein [MCVE]. Und es wird nicht funktionieren, weil Sie 'plt.show()' aufrufen, bevor Sie Ihre 'my_plot2'Funktion aufrufen. – ImportanceOfBeingErnest

Antwort

0

nach http://matplotlib.org/users/pyplot_tutorial.html sollten Sie nur in der Lage sein, so etwas wie dieses:

t = np.arange(0., 5., 0.2) 

# red dashes, blue squares and green triangles 
plt.plot(t, t, 'r--', t, t**2, 'bs', t, t**3, 'g^') 
plt.show() 

Sie nur die foramt verwenden: (x,y, style, x, y, style.....) über und über

Verwandte Themen