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


Messages In This Thread
Real time graph of the temperatures and storage - by linkxxx - Aug-28-2019, 05:18 PM

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

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020