I'm going to be plotting some temperature data over time and wrote a test program to see with Matplotlib can do for me. When I plot the the date the date time does not display as I would expect, the date is output but the time is some type of counter not the time of day as expected.
Sample data:
import pandas as pd
df = pd.DataFrame([
['08/16/2019 00:00:00',70 ],['08/17/2019 00:05:00',70.5 ],
['08/17/2019 00:10:00',70.5],['08/17/2019 00:15:00',71 ],
['08/17/2019 00:20:00',72 ],['08/17/2019 00:25:00',73 ],
['08/17/2019 00:30:00',74 ],['08/17/2019 00:35:00',74.5],
['08/17/2019 00:40:00',75 ],['08/17/2019 00:45:00',74.5],
['08/17/2019 00:50:00',73 ],['08/17/2019 00:55:00',75 ],
['08/17/2019 01:00:00',72.5],['08/17/2019 01:05:00',78 ],
['08/17/2019 01:10:00',78]], columns=['Date Time', 'Temperature'])
df
Out[1]:
Date Time Temperature
0 08/16/2019 00:00:00 70.0
1 08/17/2019 00:05:00 70.5
2 08/17/2019 00:10:00 70.5
3 08/17/2019 00:15:00 71.0
4 08/17/2019 00:20:00 72.0
5 08/17/2019 00:25:00 73.0
6 08/17/2019 00:30:00 74.0
7 08/17/2019 00:35:00 74.5
8 08/17/2019 00:40:00 75.0
9 08/17/2019 00:45:00 74.5
10 08/17/2019 00:50:00 73.0
11 08/17/2019 00:55:00 75.0
12 08/17/2019 01:00:00 72.5
13 08/17/2019 01:05:00 78.0
14 08/17/2019 01:10:00 78.0
import csv
import matplotlib.pyplot as plt
import numpy as np
from datetime import datetime
path="/home/mikejs/PythonSandbox/temps.csv"
file = open(path,newline='')
reader = csv.reader(file)
header = next(reader)
dates = []
temps = []
for row in reader:
date = datetime.strptime(row[0],'%m/%d/%Y %H:%M:%S')
dates.append(date)
temps.append(float(row[1]))
plt.title("Temperatures Over Time")
plt.plot(dates,temps )
plt.ylabel('Temperatues')
plt.xlabel('Date/Time')
plt.xticks(rotation='45')
plt.tight_layout();
plt.savefig('temps.png')
plt.show()