Follow Joe Kingston's answer, but I would add that you need to convert date strings to datetime objects, which can easily be done using the datetime module, and then convert them to matplotlib dates, represented as float (which can then be formatted as desired) .
import datetime as dt import matplotlib as mpl some_time_str = '2010-12-20 05:00:00' some_time_dt = dt.datetime.strptime(some_time_str, '%Y-%m-%d %H:%M:%S') some_time_num = mpl.dates.date2num(some_time_dt)
If you start with an array filled with temporary lines, you can do something like:
time_str_list = ['2010-12-20 05:00:00','2010-12-20 05:30:00'] time_num_list = map( lambda x: mpl.dates.date2num(dt.datetime.strptime(x, '%Y-%m-%d %H:%M:%S')), time_str_list) #[734126.20833333337, 734126.22916666663]
source share