Python在同一个图上绘制了几个图

时间:2017-03-06 22:35:25

标签: python matplotlib subplot

我有一个名为df的数据框:

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

我想绘制加热器和按平均每小时分组的热平均值(平面是一个IdBox编号)。

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

1 个答案:

答案 0 :(得分:0)

根据http://matplotlib.org/users/pyplot_tutorial.html你应该能够做到这样的事情:

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

你只需要反复使用foramt:(x,y, style, x, y, style.....)