I am using python3.6 - 32 bit for Windows. I want to divide all data in column 0 by 3600 before plotting it. How do I do this? Please see code below. PS code works fine as is, just want to get my time data from sec. to hours (hence 3600 value) all in the same program.
import matplotlib.pyplot as plt
import csv
x = []
y = []
with open('C:\Log_data5.dat','r') as csvfile:
plots = csv.reader(csvfile, delimiter=',')
for row in plots:
x.append(float(row[0]))
y.append(float(row[5]))
plt.plot(x,y, label='Loaded from file!')
plt.ylabel('Temperature(°C)')
plt.xlabel('Time(s)')
plt.title('Temp vs. Time')
plt.ticklabel_format(style='plain')
plt.ticklabel_format(useOffset=False)
plt.legend()
plt.show()
I think you could just change x.append(float(row[0]))
to x.append(float(row[0])/3600)
.
This will divide your row[0]
(i.e. time) values by 3600 prior to inserting them into your x-axis list.
Don't forget to update your x-axis label units from s
to hr
.