Converting dates into a suitable format for MatPlotLib

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Converting dates into a suitable format for MatPlotLib

Michael Morrone

Hello,

 

I have a series of dates of the form (YYYY, mm, dd, (hh/24)) as output from the module jd2gcal.  hh/24 = the fractional part of a day represented as a decimal, i.e. 12/24 = 0.5 so my data would look like this for December 21, 2015 at 12:00 UTC:

 

                (2015, 12, 21, 0.5)

 

Is there a way to convert the above string into a date format suitable for plotting in MatPlotLib?  There doesn’t seem to be a format representation for a fractional day in Python as far as I can tell.  I’m a newbie, so type slowly. J

 

Many thanks for any assistance!

 

Regards,

Mike

 

Michael Morrone

Meteorologist

Oceanweather, Inc.

[hidden email]

 


_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Converting dates into a suitable format for MatPlotLib

Paul Hobson-2
You'll need to write your own parser. Something like:

from datetime import datetime
def parse_date_tuple(dt):
    year, month, day, _day_fraction = dt # unpack the tuple
    hour = _day_fraction * 24
    return datetime(year, month, day, hour)

So you could apply that to a list of your date-tuples like this:

dates = numpy.array([parse_date_tuple(dt) for dt in date_tuple_list])

I didn't test any of this, so caveat emptor and whatnot.


On Thu, Jan 12, 2017 at 3:03 PM, Michael Morrone <[hidden email]> wrote:

Hello,

 

I have a series of dates of the form (YYYY, mm, dd, (hh/24)) as output from the module jd2gcal.  hh/24 = the fractional part of a day represented as a decimal, i.e. 12/24 = 0.5 so my data would look like this for December 21, 2015 at 12:00 UTC:

 

                (2015, 12, 21, 0.5)

 

Is there a way to convert the above string into a date format suitable for plotting in MatPlotLib?  There doesn’t seem to be a format representation for a fractional day in Python as far as I can tell.  I’m a newbie, so type slowly. J

 

Many thanks for any assistance!

 

Regards,

Mike

 

Michael Morrone

Meteorologist

Oceanweather, Inc.

[hidden email]

 


_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users



_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users