【问题标题】:Python several plots on the same plotsPython 在同一个图上绘制了几个图
【发布时间】:2017-07-26 23:41:41
【问题描述】:

我有一个名为 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])

【问题讨论】:

标签: python matplotlib subplot


【解决方案1】:

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

您只需一遍又一遍地使用格式:(x,y, style, x, y, style.....)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多