Here's a code snippet I found somewhere that demonstrates the use:
def make_datetime(s, fmt='%Y-%m-%d %H:%M'):
'''convert string to datetime'''
ts = time.mktime(time.strptime(s, fmt))
return datetime.fromtimestamp(ts)
Warning, this is very slow, if you need to do a lot of conversions it
will take some time.
Bill
Jonathan Taylor wrote:
You can use python's time module to parse dates, see time.strptime and
time.strftime.
Jonathan
Marquardt, Colin wrote:
[Repost, sorry if you get this twice.]
Hi guys,
in my quest for a better gnuplot replacement, I came across matplotlib
yesterday.
I really like it, big thanks to the developers.
It was pretty easy to port over a gnuplot command file. There are
two things that could have been easier still though:
* My data file consists of a date (in ISO format) and integers. Parsing
the date was a bit of work. I understand that python's datetime
doesn't
provide any parsing of dates - but maybe matplotlib should have some
functions for that then? FWIW, here is how gnuplot does this (adapted
from http://t16web.lanl.gov/Kawano/gnuplot/datetime-e.html):
set xdata time
set timefmt "%Y-%m-%d"
set format x "%Y-%m"
In my matplotlib script, I'm now doing:
mydate = [int(elem) for elem in vals_line[0].split('-')]
datenums.append(date2num(datetime.date(mydate[0], mydate[1],
mydate[2])))
[...]
plotline = plot_date(datenums, data)
* gnuplot has a plot style "steps"
(http://t16web.lanl.gov/Kawano/gnuplot/intro/style-e.html) - I
could only fake that with with extra "dummy" points in matplotlib
as I understand it. It would be nice if matplotlib could do this
for me.
Cheers,
Colin
-------------------------------------------------------
All the advantages of Linux Managed Hosting--Without the Cost and Risk!
Fully trained technicians. The highest number of Red Hat certifications in
the hosting industry. Fanatical Support. Click to learn more
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users