如何在python中的矩形框图上绘制温度(热梯度)? [蟒蛇]

时间:2018-08-24 11:35:53

标签: python matplotlib plot temperature

随着时间的推移,我正在从连接到Odroid XU4上每个大型CPU内核的4个传感器收集温度值。我想在4个大核的框图上绘制温度(热梯度),如下所示:

enter image description here

到目前为止,我在同一问题上一直关注another answer,但我无法为我的解决方案提供解决方案。我能够读取从CPU内核的热传感器(传感器0-4)发送的温度值,如下所示:

def read_file(fname):
    import string
    with open(fname) as f:
        lines = [line.rstrip('\n') for line in f]
    sensor0 = []
    sensor1 = []
    sensor2 = []
    sensor3 = []
    for each_line in lines:
        if "sensor0" in each_line:
            this_value = each_line[10:len(each_line)]
            sensor0.append(this_value)
        if "sensor1" in each_line:
            this_value = each_line[10:len(each_line)]
            sensor1.append(this_value)
        if "sensor2" in each_line:
            this_value = each_line[10:len(each_line)]
            sensor2.append(this_value)
        if "sensor3" in each_line:
            this_value = each_line[10:len(each_line)]
            sensor3.append(this_value)
    print("\nProcessed file!\n" + fname)
    reduction = 1000
    sensor0 = map(float, sensor0)
    sensor0V = [temp / reduction for temp in sensor0]
    sensor1 = map(float, sensor1)
    sensor1V = [temp / reduction for temp in sensor1]
    sensor2 = map(float, sensor2)
    sensor2V = [temp / reduction for temp in sensor2]
    sensor3 = map(float, sensor3)
    sensor3V = [temp / reduction for temp in sensor3]

    plot(sensor0V,"Time interval of 0.1 sec on Sensor 0")
    plot(sensor1V,"Time interval of 0.1 sec on Sensor 1")
    plot(sensor2V,"Time interval of 0.1 sec on Sensor 2")
    plot(sensor3V,"Time interval of 0.1 sec on Sensor 3")

def plot(Y,xLabel):
    import matplotlib.pyplot as plt
    plt.plot(Y)
    plt.ylabel('Temperature variance over time (0.1 sec)')
    plt.xlabel(xLabel)
    plt.show()

def main():
    fname = "Temp_all.txt"
    read_file(fname)


if __name__ == '__main__':
    main()

当前,使用上述代码,我实现了以下目标:

enter image description here

有人可以帮助我在大铁芯方框图的顶部绘制温度随时间变化的热梯度吗?

每个传感器列表中存储的日期如下:

  

sensor0 = ['6500','7000','8500','8600']。 6500表示   温度为摄氏65度。

下图显示了一个热梯度示例:

enter image description here

0 个答案:

没有答案