I'm struggling to figure out how to format my data so that I can use dates
as x-data. 

I've tried the pylab examples and they execute beautifully on my Windoze and
Linux boxes. But when I try to plot data on my own, it doesn't work. 

Using api example date_demo.py as a starting point. This appears to be stock
price for Google from 2004 to 2008. Here are some clues:

 In [7]: q = np.load(datafile)
 In [8]: q
 Out[7]:
rec.array([ (datetime.date(2004, 8, 19), 100.0, 104.06, 95.959999999999994,
100.
34, 22351900L, 100.34),
       (datetime.date(2004, 8, 20), 101.01000000000001, 109.08, 100.5,
108.31, 1
1428600L, 108.31),
       (datetime.date(2004, 8, 23), 110.75, 113.48, 109.05,
109.40000000000001,
9137200L, 109.40000000000001),
       ...,
       (datetime.date(2008, 10, 10), 313.16000000000003, 341.88999999999999,
310
.30000000000001, 332.0, 10597800L, 332.0),
       (datetime.date(2008, 10, 13), 355.79000000000002, 381.94999999999999,
345
.75, 381.01999999999998, 8905500L, 381.01999999999998),
       (datetime.date(2008, 10, 14), 393.52999999999997, 394.5, 357.0,
362.70999
999999998, 7784800L, 362.70999999999998)],
      dtype=[('date', '|O4'), ('', '|V4'), ('open', '<f8'), ('high', '<f8'),
('l
ow', '<f8'), ('close', '<f8'), ('volume', '<i8'), ('adj_close', '<f8')])

  In [9]: r = q.view(np.recarray)
  In [10]: r.date
  Out[10]: array([2004-08-19, 2004-08-20, 2004-08-23, ..., 
          2008-10-10, 2008-10-13, 2008-10-14], dtype=object)

So it appears that the dtype of the date column is '|O4'

I tried to import my own data. It looks like 
   2005-03-04,0.923115796
   2005-03-05,0.915828724
   2005-03-06,0.442521474
   2005-03-07,0.997096213
   2005-03-08,0.867752118
And to import, I use recarray
  myarray = np.loadtxt(fullfile, dtype=[('date', '|O4'), ('ydata',
'float')], delimiter = ',')
  rx = myarray.view(np.recarray)

Data imports fine. But when I go to plot, I get the following error
  ValueError: setting an array element with a sequence.
  WARNING: Failure executing file: <bogus.py>

This makes me think I don't quite have everything formatted correctly. Any
ideas?

Bill Eaton



------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate 
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the 
lucky parental unit.  See the prize list and enter to win: 
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to