I have a csv file with aprox. 3000 lines and the following format:
Timestamp,PV Generation (W)
2019-01-01 00:00:00,616.54
2019-01-01 00:15:00,617.75
2019-01-01 00:30:00,752.56
I am using pandas to read it using:
columnnames = ['Timestamp','PV Generation (W)']
df = pandas.read_csv(filename, sep=',', engine='python', names=columnnames,index_col=None)
timestamp = df['Timestamp']
pvgeneration = df['PV Generation (W)']
pvgenerationlist=pvgeneration.tolist() #create a list with pvgeneration column
timestamplist=timestamp.tolist() #create a list with timestamp column
because the first row of each column is the header, i remove the first element of each list with:
timestamplist.pop(0)
pvgenerationlist.pop(0)
The pvgeneration values are a string, so i change them to float:
pvgenfloat = []
for item in pvgenerationlist:
pvgenfloat.append(float(item))
I now have two lists left that i wish to plot using matplotlib. I want the Y axis to have the float PV generation values, and the X axis to have some of the timestamp string values.
plt.plot(timestamplist,pvgenfloat)
gives a mess because it plots 3000 timestamps in the X axis.
By hovering using the mouse on the chart i can read the values under it: x=2019-01-01 00:00:00 y=616.54
So i attempt to use plt.xticks to plot only the first and last string element of my timestamplist using:
xlisttoplot=[''] * len(timestamplist) #i create a new list to plot with same length but blank elements
xlisttoplot[0]=timestamplist[0] #i keep the first element of the timestamp list which is 2019-01-01 00:00:00
xlisttoplot[-1]=timestamplist[-1] #and i also keep the last one
plt.xticks(timestamplist,xlisttoplot,rotation=45,size = 8)
The above works, it plots only the first and last value in X, but now i cant use the mouse to hover on the values. By hovering it reads: x= y=616.54
I need to read the data by hovering. Any clue on how to solve this, or do the same thing in a different way? Thank you