Python Forum
matplotlib plot to time - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: matplotlib plot to time (/thread-7266.html)



matplotlib plot to time - kiyoshi7 - Jan-01-2018

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?


RE: matplotlib plot to time - Windspar - Jan-02-2018

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)