使用感应帽和matplotlib模块绘制温度传感器的图形

时间:2018-03-14 18:31:08

标签: python list loops matplotlib valueerror

如果有人可以帮助我,那我想完成的项目有点困难,项目就是用matplotlib为感应帽温度传感器创建一个图形。

我能做的是使用以下代码创建图表;

import matplotlib.pyplot as plt

plt.rcParams['toolbar'] = 'None'
plt.plot([], [], 'b-')#Plots go inside the square brackets

plt.axis([0, 24, -5, 30])
plt.ylabel('Tempreture')#Label of the Y axis 'ylabel'
plt.xlabel('Time (Hours)')#Label of the X axis 'xlabel'

plt.show()#Displays the graph

我还可以通过这个简单的循环收集大量的温度;

from sense_hat import SenseHat

temperature = []
while True:
    temp = sense.get_temperature()
    temp1 = round(temp, 2)
    temperature.append(temp1)

但我的问题是把这两段代码放在一起,因为我试图将我的列表温度插入到y轴但是它出现了错误

ValueError: x and y must have the same first dimension

所以,如果有人能帮助我为我的感觉帽温度传感器创建一个图表,我会很高兴。

0 个答案:

没有答案