Python Forum
Real time graph of the temperatures and storage
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Real time graph of the temperatures and storage
#1
import serial # import Serial Library import numpy as np # Import numpy import adafruit_max31856 import matplotlib.pyplot as plt #import matplotlib library from drawnow import * import datetime import math import csv T1= [] T2=[] plt.ion() cnt=0 ##def animate(line): ## pullData = open('C:\\Users\\Alphinity\\Desktop\\python3\\signalSerial.txt','r').read() ## dataArray = pullData.split('\n') ## xar=[] ## yar=[] ## for eachLine in dataArray: ## if len(eachLine)>1: ## x,y = eachLine.split(',') ## xar.append(float(x)) ## yar.append(float(x)) ## ## ax1.plot(xar,yar) ##ani = animation.FuncAnimation(fig,animate, interval=100) def makeFig(): #Create a function that makes our desired plot plt.ylim(80,90) #Set y min and max values plt.title('My Live Streaming Sensor Data') #Plot the title plt.grid(True) #Turn the grid on plt.ylabel('Temp T1') #Set ylabels plt.plot(T1, 'ro-', label='Degrees F') #plot the temp1 plt.legend(loc='upper left') #plot the legend plt2=plt.twinx() #Create a second y axis plt.ylim(93450,93525) #Set limits of second y axis- adjust to readings you are getting plt2.plot(T2, 'b^-', label='Degrees F') #plot temp2 data plt2.set_ylabel('Degrees F') #label second y axis plt2.ticklabel_format(useOffset=False) plt2.legend(loc='upper right') #plot the legend ## user-defined params serialPort = 'COM3' ## the serial device path = 'C:\\Users\\Alphinity\\Desktop\\python3\\' ## the output file path outputFile = "signalSerial.csv" ## the output file name ser = serial.Serial('COM3', 115200) outputFile = path + outputFile f = open(outputFile,'w') #create and/or open a file and give the command to write the informations f.write(outputFile) #write inside the file created f.close() print ("Writing the serial stream into file: " + outputFile) print (" [to see the stream: tail -f '+outputFile+' ]") print (" [to exit: ctrl+c (the elegant way :) ]") while True: # While loop that loops forever line = ser.readline() string = line T1 = float(string[0]) #Convert first element to floating number and put in T1 T2 = float(string[1]) #Convert second element to floating number and put in T2 T1.append(T1) T2.append(T2) drawnow(makeFig) plt.pause(.000001) cnt=cnt+1 if(cnt>50): T1.pop(0) T2.pop(0) if (string != ''): f = open(outputFile, 'a') f.write(str(string)) f.write("\n") f.close() #plt.show(string.decode()) #print (string) ## uncomment to see the values in the terminal print(string.decode()) ## ctrl+c to stop the code valueRead.decode().strip()
-----------------------------
I'm getting always this error, I need to show in real time a graph and save in a file everytime new.

Error:
T1.append(T1) #Build our tempF array by appending temp readings AttributeError: 'float' object has no attribute 'append' ----------------------
Thank you so much for how can help me
Reply
#2
T1 and T2 are floats, not lists. You are trying to append a value to floats, this is why the error raises.
At least, try to replace
T1 = float(string[0]) #Convert first element to floating number and put in T1 T2 = float(string[1]) #Convert second element to floating number and put in T2 T1.append(T1) T2.append(T2)
with
T1.append(string[0]) T2.append(string[1])
Reply
#3
(Aug-28-2019, 05:18 PM)linkxxx Wrote: [python]

T1= []
T2=[]
plt.ion()
cnt=0

T1 = float(string[0]) #Convert first element to floating number and put in T1
T2 = float(string[1]) #Convert second element to floating number and put in T2
T1.append(T1)
T2.append(T2)

You are confusing Python compiler by using same variable name. Try using different variable name to store the float value and try append to T1 and T2 list
Reply
#4
Thank you so much to all for the answer, I found the problem, and now I'm getting both the temperatures, only the strange thing is that are not the measurements, because the temperature is around 25 degrees, and on the graph appear 40-45, I'm attaching the code if someone maybe know the answer https://pastebin.com/DCiXqcZG .
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  uploading files from a ubuntu local directory to Minio storage container dchilambo 0 2,011 Dec-22-2023, 07:17 AM
Last Post: dchilambo
  Upload Files to Azure Storage Container phillyfa 6 5,683 Dec-22-2023, 06:11 AM
Last Post: Pedroski55
  first time use plot - I get empty graph korenron 6 6,025 Feb-04-2023, 02:14 PM
Last Post: deanhystad
  Non-blocking real-time plotting slow_rider 5 12,312 Jan-07-2023, 09:47 PM
Last Post: woooee
  Real time database satyanarayana 3 2,921 Feb-16-2022, 01:37 PM
Last Post: buran
  Real time data satyanarayana 3 38,245 Feb-16-2022, 07:46 AM
Last Post: satyanarayana
  Real time Detection and Display Gilush 0 2,605 Feb-05-2022, 08:28 PM
Last Post: Gilush
  Real-Time output of server script on a client script. throwaway34 2 3,351 Oct-03-2021, 09:37 AM
Last Post: ibreeden
  Real Time Audio Processing with Python Sound-Device not working Slartybartfast 2 9,375 Mar-14-2021, 07:20 PM
Last Post: Slartybartfast
Question I can't get my real-time chart with Python (Help!) Bastian_ElProfe 1 3,350 Jan-20-2021, 01:34 PM
Last Post: wostan

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.