Converting dates into a suitable format for MatPlotLib

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.

mikem at oceanweather.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20170112/775ead89/attachment.html>

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 <mikem at oceanweather.com> 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.

mikem at oceanweather.com

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
Matplotlib-users Info Page

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20170112/d7643068/attachment.html&gt;