SHARE
TWEET

itry

a guest Nov 16th, 2019 95 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import matplotlib
  2. import matplotlib.pyplot as plt
  3. import matplotlib.dates as mdates
  4. import tkinter
  5.  
  6. from datetime import datetime, date, timedelta
  7.  
  8.  
  9. matplotlib.use('TkAgg')
  10.  
  11. def get_data():
  12.     all_data = []
  13.  
  14.     with open('data.csv', 'r') as file:
  15.         line_num = 1
  16.         for line in file:
  17.             data = {}
  18.             line = line.strip()
  19.             data['timestamp'] = line.split(',')[0]
  20.             data['day'] = line.split(',')[1]
  21.             data['time'] = line.split(',')[2]
  22.             data['filepath'] = line.split(',')[3]
  23.             all_data.append(data)
  24.  
  25.     return all_data
  26.  
  27. def get_x_delta():
  28.     x_range = []
  29.     start_date = datetime.strptime(all_data[0]['day'], '%Y-%m-%d')
  30.     last_date = datetime.strptime(all_data[-1]['day'], '%Y-%m-%d')
  31.  
  32.     days = mdates.drange(start_date,last_date, timedelta(days=1))
  33.     return days
  34.  
  35. def get_y_stamp():
  36.     y = []
  37.     for entry in all_data:
  38.         time = datetime.strptime(entry['timestamp'], '%Y:%m:%d %H:%M:%S')
  39.         y.append(time)
  40.     return y
  41.        
  42. all_data = get_data()
  43.  
  44. x_range = get_x_delta()
  45. y = get_y_stamp()
  46.  
  47.  
  48. plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d'))
  49. plt.gca().xaxis.set_major_locator(mdates.DayLocator(interval=1))
  50.  
  51. plt.gca().yaxis.set_major_locator(mdates.HourLocator())
  52. plt.gca().yaxis.set_major_formatter(mdates.DateFormatter('%H:%M'))
  53. plt.plot(x_range,y)
  54. plt.gcf().autofmt_xdate()
  55. plt.show()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top