2

I'm trying to plot a time series from the csv file. eg. datalog.csv contains:

19:06:17.188,12.2

19:06:22.360,3.72

19:06:27.348,72

19:06:32.482,72

19:06:37.515,74

19:06:47.660,72

tried some thing like below:

import numpy as np

import matplotlib.pyplot as plt

import matplotlib.dates as mdates


time, impressions = np.loadtxt("datalog_new.csv", unpack=True,

        converters={ 0: mdates.strptime2num('%H:%M:%S.%f')})


plt.plot_date(x=time, y=impressions)

plt.show()

but could not parse the time, mdates.strptime2num('%H:%M:%S.%f')

Any suggestions are greatly appreciated.

1 Answer 1

3

You have to use bytespdate2num function to read csv file (because you read the file in binary mode):

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.dates import bytespdate2num

time, impressions = np.loadtxt("datalog_new.csv",
 unpack=True, delimiter=',', converters={0: bytespdate2num('%H:%M:%S.%f')})

plt.plot_date(x=time, y=impressions)
plt.show()

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.