Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ggplot python handling time data over many weeks at hourly resolution

I am plotting journey time for a series of roads at hourly resolution, with data over a few weeks.

I can plot using unix time, but that isn't very intuitive. This is 7 days worth of data.

enter image description here

I used a function to manipulate the time field in order to give the date and hour:

def plot_time(time):
    return time.strftime('%Y-%m-%d-%H')

However, this results in ggplot throwing a value error when trying to plot:

ValueError: invalid literal for float(): 2016-04-13-00

Is there a simpler means of displaying date and some hour?

Alternatively I could plot unix time with a date scale on the axis but it would be nice to have some hour resolution on the axis.

like image 668
LearningSlowly Avatar asked Apr 23 '16 14:04

LearningSlowly


1 Answers

POSIXct was the key here as bVa said.

ggplot(aes(x=as.POSIXct(epoch_time,origin="1970-01-01"),y=lambda)

Once the epoch time was formated POSIXct, it was possible to use scale_x_datetime()

I settled on:

+ scale_x_datetime(breaks=date_breaks("1 day"))
like image 128
LearningSlowly Avatar answered Nov 15 '22 10:11

LearningSlowly