0

I'm doing a project which will measure the temp in a fridge over a period of 2 weeks and I want to graph the temperature using matplotlib, but since I write to a csv file and then with a other script I read from the csv file I get a lot of data points on my x-axis which clutters it and it isn't readable anymore.

I also want to try and update it live to be able to view from the outside. Basically I want a graph that only shows the last 12 hours of the data.

from itertools import count
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
from matplotlib import dates as mpl_dates

plt.style.use('seaborn')

def animate(i):
     data = pd.read_csv('data.csv')

     datumtijd = data['datumtijd']
     temp = data['temp']
     plt.cla()

     plt.plot(datumtijd, temp, label='Channel 1')

     plt.gcf().autofmt_xdate()
     plt.legend(loc='upper left')
     plt.tight_layout()


ani = FuncAnimation(plt.gcf(), animate, interval=1000)
plt.tight_layout()
plt.show()

this is what I get now after 2 minutes. it already barely readable: example of 2min of data

Jason Aller
  • 3,475
  • 28
  • 40
  • 37

0 Answers0