Home > front end >  Why doesn't my plot display date and time correctly?
Why doesn't my plot display date and time correctly?

Time:07-16

I am attempting to create a plot with Temperature on the Y axis, and date and time on the X Axis. My data appears to plot correctly, however the date and time does not. My date and time data is in column 0 of my csv, Labeled in the format m/d/Y H:M:S, example: 6/13/2022 2:36:00 PM. Instead of this expected format Time appears as simple integers starting from 0 and going up to 10000.

#Import libraries
from dataclasses import dataclass
from textwrap import indent
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import pandas as pd
import numpy as np
import csv
from datetime import datetime


#read the CSV

df = pd.read_csv(r"C:\Users\pmay\Desktop\Python\LOGRPT61.csv", parse_dates=True )
change_format = date_sr.dt.strftime('%m/%d/%Y %H:%M:%S')

#Identify column data
ctrlTC = df.iloc[:,[1,2,3,4,5,6,7,8,]]


#Label Axes
plt.xlabel('Time')
plt.ylabel('Temp [deg C]')

#Plot the data
plt.plot(ctrlTC)# kind='line')

plt.rcParams["figure.figsize"] = [10, 7]
plt.rcParams["figure.autolayout"] = True
line1, = plt.plot([1], label="Control TC1")
line2, = plt.plot([2], label="Control TC2")
line3, = plt.plot([3], label="Control TC3")
line4, = plt.plot([4], label="Control TC4")
line5, = plt.plot([5], label="Control TC5")
line6, = plt.plot([6], label="Control TC6")
line7, = plt.plot([7], label="Control TC7")
line8, = plt.plot([8], label="Control TC8")

plt.legend(loc="upper left")

Which results in:

enter image description here

  • Related