Python Forum

Full Version: matplotlib plot to time
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hi, I'm plotting a lot of data with python, but I'd like to set the x axis to plot using the time and date that my data was gathered and I haven't been able to figure it out. I looked at this page that seemed like it would help but I don't understand how the code works. basically I the time and date is in a list within another list and is formatted like this: year.month.day.hour.min.sec
the list where everything is contained looks 'like this: data = [['47. 12. 23. 14. 33. 25', ..., ' 47. 12. 31. 20. 1. 13 '],[data], ..., [data]]

how do I transform data[0](the time and date) into something matplotlib can use to set the x axis?
from matplotlib import dates
import datetime

d = '47. 12. 23. 14. 33. 25'

dt = datetime.datetime.strptime(d, '%y. %m. %d. %H. %M. %S') 
print(dt.date(), dt.time())

fds = dates.date2num(dt)
print(fds)