On Fri, Apr 17, 2009 at 5:22 PM, Andrew Romero <romero...@yahoo.com> wrote:
> The script plottest.py.txt reads the data file (out.txt) and creates the
> plot (myfig.png); however,
> I am unable to format the dates ... they always print as floats .. help
>
> the files plottest.py.txt, out.txt and myfig.png are attached
>
You can use the csv2rec function with a converter function to convert your
timestamps to datetime instances. Here is an example:
import datetime
import numpy as np
import matplotlib.mlab as mlab
import matplotlib.dates as mdates
import matplotlib.pyplot as plt
def todate(s):
'convert a unix timestamp string to a datetime instance'
return datetime.datetime.fromtimestamp(float(s))
r = mlab.csv2rec('out.txt', names='date,val1,val2,val3,val4',
delimiter=' ', converterd={'date':todate})
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(r.date, r.val1, label='val1')
ax.plot(r.date, r.val2, label='val2')
ax.plot(r.date, r.val3, label='val3')
ax.xaxis.set_major_formatter(mdates.DateFormatter('%H:%M:%S'))
ax.fmt_xdata = mdates.DateFormatter('%Y-%m-%d %H:%M:%S')
leg = ax.legend(fancybox=True, shadow=True)
leg.get_frame().set_alpha(0.5)
fig.autofmt_xdate()
plt.show()
JDH
------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today.
Use priority code J9JMT32. http://p.sf.net/sfu/p
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users