Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import matplotlib
- import matplotlib.pyplot as plt
- import matplotlib.dates as mdates
- import tkinter
- from datetime import datetime, date, timedelta
- matplotlib.use('TkAgg')
- def get_data():
- all_data = []
- with open('data.csv', 'r') as file:
- line_num = 1
- for line in file:
- data = {}
- line = line.strip()
- data['timestamp'] = line.split(',')[0]
- data['day'] = line.split(',')[1]
- data['time'] = line.split(',')[2]
- data['filepath'] = line.split(',')[3]
- all_data.append(data)
- return all_data
- def get_x_delta():
- x_range = []
- start_date = datetime.strptime(all_data[0]['day'], '%Y-%m-%d')
- last_date = datetime.strptime(all_data[-1]['day'], '%Y-%m-%d')
- days = mdates.drange(start_date,last_date, timedelta(days=1))
- return days
- def get_y_stamp():
- y = []
- for entry in all_data:
- time = datetime.strptime(entry['timestamp'], '%Y:%m:%d %H:%M:%S')
- y.append(time)
- return y
- all_data = get_data()
- x_range = get_x_delta()
- y = get_y_stamp()
- plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d'))
- plt.gca().xaxis.set_major_locator(mdates.DayLocator(interval=1))
- plt.gca().yaxis.set_major_locator(mdates.HourLocator())
- plt.gca().yaxis.set_major_formatter(mdates.DateFormatter('%H:%M'))
- plt.plot(x_range,y)
- plt.gcf().autofmt_xdate()
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement