I am doing my school Arduino project at home, and the teacher asks me to visualize my data for him. On my x-axis, I have more than 20K time points need to show, and I try to set a range for it.
The graph I am trying to achieve:
What I got up till now:
It is very clear I am doing something wrong, and I have researched for a way to solve it.
The # part of my plotting part is what I learned from the internet, but they do not work here.
Please help me and if anything in question is unclear, let me know!
import csv
import matplotlib.pyplot as plt
from datetime import datetime
header = []
data = []
path="DATALOG.csv" #CHANGE filename to match file
file = open(path, newline='')
reader=csv.reader(file)
header=next(reader) #This reads the first row and stores the words in header.
data=[row for row in reader] #This reads the rest and store the data in a list
file.close() #closes the file when complete
# This function will print the headings with their index. Helpful when dealing with many columns
def print_header():
for index, column_header in enumerate(header):
print(index, column_header)
# I want the high and low temperatures in New Glasgow for June 2010
# Key headings
# 0 date/time
# 1 temperature
# 2 humidity %
# 3 light level%
days = []
light = []
for row in range (len(data)):
day = data[row][0]
lights = data[row][3]
current_date=datetime.strptime(data[row][0], "%A %H:%M:%S %d/%m/%Y")
light.append(float(lights)) #store the day’s high temp in list
#store the day’s low temp in list
days.append(str(day))
fig = plt.figure(dpi=128, figsize = (50, 6))
#x = [dc[0] for dc in days]
#xticks = range(0,len(x),10)
#xlabels=[x[index] for index in xticks]
#xticks.append(len(x))
#xlabels.append(days[-1][0])
#ax.set_xticks(xtick)
#ax.set_xticklabels(xlabels,rotation=40)
plt.plot(days,light,c = 'red',label = 'temprature')
plt.title("LIGHT")
plt.xlabel('days',fontsize = 5)
#ax.plot(np.arange('Wednesday 12:00:00 08/01/2020',' Thursday 11:58:10 09/01/2020'), range(10))
fig.autofmt_xdate()
plt.ylabel('light (%)', fontsize = 12)
plt.tick_params(axis='both', which='major', labelsize = 10)
plt.legend()
plt.show()
plt.savefig('plot.png')