python实时显示温度变化_python实时温度绘制
我目前正在做一個項目,它需要實時監(jiān)控各種量,如溫度、壓力、濕度等。我正在采用一種方法,即使用matplotlib和drwnow繪制一個圖形。在HOST = "localhost"
PORT = 4223
UID1 = "tsJ" # S1
from tinkerforge.ip_connection import IPConnection
from tinkerforge.bricklet_ptc import BrickletPTC
import numpy as np
import serial
import matplotlib
from matplotlib.ticker import ScalarFormatter, FormatStrFormatter
import matplotlib.pyplot as plt
from matplotlib import style
style.use('ggplot')
from drawnow import *
# creating arrays to feed the data
tempC1 = []
def makeafig():
# creating subplots
fig1 = plt.figure(1)
a = fig1.add_subplot(111)
#setting up axis label, auto formating of axis and title
a.set_xlabel('Time [s]', fontsize = 10)
a.set_ylabel('Temperature [°C]', fontsize = 10)
y_formatter = matplotlib.ticker.ScalarFormatter(useOffset=False)
a.yaxis.set_major_formatter(y_formatter)
title1 = "Current Room Temperature (Side1): " + str(temperature1/100) + " °C"
a.set_title(title1, fontsize = 10)
#plotting the graph
a.plot(tempC1, "#00A3E0")
#saving the figure
fig1.savefig('RoomTemperature.png', dpi=100)
while True:
ipcon = IPConnection() # Create IP connection
ptc1 = BrickletPTC(UID1, ipcon) # S1
ipcon.connect(HOST, PORT) # Connect to brickd
#setting the temperature from PTC bricklet
temperature1 = ptc1.get_temperature()
#processing data from a temperature sensor to 1st array
dataArray1=str(temperature1/100).split(',')
temp1 = float(dataArray1[0])
tempC1.append(temp1)
#making a live figure
drawnow(makeafig)
plt.draw()
這是我在互聯(lián)網(wǎng)上發(fā)現(xiàn)的很好的方法,它正在起作用。我所面臨的唯一問題是,如果我為其他傳感器制作更多的陣列,那么它會耗費(fèi)更多的時間,而且與秒表相比,所繪制的繪圖會滯后于實時。在
對于任何一個有效率的實時圖像獲取方法都是有效的。
或者任何命令來清除已經(jīng)打印的數(shù)組值?在
如果有人能幫我解決這個問題,我將不勝感激。在
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎總結(jié)
以上是生活随笔為你收集整理的python实时显示温度变化_python实时温度绘制的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 共阳数码管段码表_简单共阴极数码管电路图
- 下一篇: android studio1.5 fo