Re: [SciPy-user] Converting arrays to dates for plot_date()
Thank you John, I tried that and got the error message : TypeError: descriptor 'date' requires a 'datetime.datetime' object but received a 'numpy.float64' but using datetime() rather than datetime.date() seems to work. fyi. y'all have a great community here. I've asked two questions in the last few days and was answered quickly and correctly on both occasions. thanks, - dharhas
"John Hunter" <jdh2358@gmail.com> 05/01/08 3:49 PM >>> On Thu, May 1, 2008 at 3:15 PM, Dharhas Pothina <Dharhas.Pothina@twdb.state.tx.us> wrote:
to generate the list of dates for plot_date()
but I can't work out how to convert
year = array([2006.0,2007.0]) month = array([11,12]) day = array([1,2])
dates = [datetime.date(y,m,d) for y,m,d in zip(year, month, day)] plot(dates, data) # requires 0.91.2 or svn -- else use date2num and plot_date JDH _______________________________________________ SciPy-user mailing list SciPy-user@scipy.org http://projects.scipy.org/mailman/listinfo/scipy-user
On Fri, May 2, 2008 at 7:21 AM, Dharhas Pothina <Dharhas.Pothina@twdb.state.tx.us> wrote:
Thank you John, I tried that and got the error message :
TypeError: descriptor 'date' requires a 'datetime.datetime' object but received a 'numpy.float64'
but using datetime() rather than datetime.date() seems to work.
I think the problem may be that you had floats rather than ints in your "year" array. For example, the following does work: In [34]: data = array([1,2]) In [35]: year = array([2006,2007]) In [36]: month = array([11,12]) In [37]: day = array([1,2]) In [38]: dates = [datetime.date(y,m,d) for y,m,d in zip(year, month, day)] In [39]: dates Out[39]: [datetime.date(2006, 11, 1), datetime.date(2007, 12, 2)]
fyi. y'all have a great community here. I've asked two questions in the last few days and was answered quickly and correctly on both occasions.
Glad to help. JDH
On Fri, May 2, 2008 at 8:15 AM, John Hunter <jdh2358@gmail.com> wrote:
On Fri, May 2, 2008 at 7:21 AM, Dharhas Pothina
<Dharhas.Pothina@twdb.state.tx.us> wrote:
Thank you John, I tried that and got the error message :
TypeError: descriptor 'date' requires a 'datetime.datetime' object but received a 'numpy.float64'
but using datetime() rather than datetime.date() seems to work.
I think the problem may be that you had floats rather than ints in your "year" array.
Actually, I think the problem is that you did import datetime and he did from datetime import datetime but neither of you actually showed the import statements you used. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco
participants (3)
-
Dharhas Pothina -
John Hunter -
Robert Kern