Python Forum
Func Animation not displaying my live graph
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Func Animation not displaying my live graph
#1
This code is error-free but i don't know what i am not doing correctly that i can't get a live graph. Any help or direction would be appreciated.

import matplotlib
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib.animation import FuncAnimation 
from itertools import count
from matplotlib.figure import Figure

global anim 
 # Creating the animation Method
def animation(i):
    
    filename = '/home/pi/Work_Files/Project/Data_files/sensor_data.csv'
    data_read = open(filename)
    
    
    Date = list()
    Time = list()
    ct = get_ctemp() 
    ft = get_ftemp()  
    humi = get_humidity() 
    
    
    for line in data_read:
        row = line.split(',')
        Date_now = row[0]
        time_now = row[1]
        temperature_now = row[2]
        fahrenheit_now = row[3]
        humidity_now = row[4]
        
        date_new = datetime.date.strftime(my_date, "%b %d %Y")
        time_new = datetime.date.strftime(my_date, "%H:%M")
        
 # Data Variables. Append values to keep graph dynamic
        try:
            Date.append(Date_now)
            Time.append(time_now)
            ct.append(float(temperature_now))
            ft.append(float(fahrenheit_now))
            humi.append(float(humidity_now))
        except:
            print("don't know")
     
        plt.style.use('fivethirtyeight')
        fig = plt.figure(figsize=(8,8))
        

        plt.subplot(3,1,1)
        plt.plot(Time, ct, 'bo', label = "Celsius")
        plt.ylabel("Temperature readings"), plt.title("Temperature Graph")
        plt.legend()

        plt.subplot(3,1,2)
        plt.plot(Time, ft, 'g-', label = "Fahrenheit")
        plt.ylabel("Fahrenheit readings"), plt.title("Fahrenheit Graph")
        plt.legend()

        plt.subplot(3,1,3)
        plt.plot(Time, humi, 'r-', label = "Humidity")
        plt.xlabel("Current Time"), plt.ylabel("Humidity readings"), plt.title("Humidity Graph")
        plt.legend()   
    
    anim = FuncAnimation(fig, animate, interval=1000, blit=True)
plt.show()
Larz60+ write Nov-14-2020, 01:35 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.

Fixed for you this time. Please use bbcode tags in future posts.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to output one value per request of the CSV and print it in another func? Student44 3 1,278 Nov-11-2022, 10:45 PM
Last Post: snippsat
  Trying to write func("abcd") -> "abbcccdddd" omm 8 3,984 Oct-24-2020, 03:41 AM
Last Post: bowlofred
  call func from dict mcmxl22 3 2,821 Jun-21-2019, 05:20 AM
Last Post: snippsat
  About [from FILE import FUNC] Nwb 7 3,524 Apr-21-2019, 02:46 PM
Last Post: snippsat
  Executing func() from a different folder ebolisa 2 2,310 Jan-14-2019, 10:18 AM
Last Post: ebolisa
  Correct number wrong position func. albry 5 5,960 Jan-11-2019, 04:01 PM
Last Post: Larz60+
  How can I return my list from a func? Mike Ru 3 3,043 Oct-22-2018, 01:15 PM
Last Post: buran
  list func in lambda mepyyeti 1 2,879 Mar-10-2018, 09:07 PM
Last Post: buran
  return variable in func mepyyeti 1 2,609 Mar-01-2018, 02:30 AM
Last Post: Larz60+
  Print func textbox instead of shell zykbee 1 5,218 Dec-06-2017, 08:22 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

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