Download notebook (.ipynb)

Scale Time#

import numpy as np

from lets_plot import *
LetsPlot.setup_html()
def time_plot(title, time, y=False):
    np.random.seed(0)
    value = np.random.normal(loc=-5, scale=6, size=len(time))
    d = {'time': time, 'value': value}
    if y:
        return ggplot(d) + geom_line(aes('value', 'time')) + scale_y_time() + ggtitle(title)
    else:
        return ggplot(d) + geom_line(aes('time', 'value')) + scale_x_time() + ggtitle(title)

def serie(start, end, duration, step = None):
    if step is None:
        step = 1 * duration
        
    return [v for v in range(start * duration, end * duration, step)]

MS = 1
SECOND = 1000 * MS
MINUTE = 60 * SECOND
HOUR = 60 * MINUTE
gggrid([
    time_plot("5 seconds", serie(0, 5000, MS, step = 5*MS)),
    time_plot("24 hours", serie(0, 24, HOUR, step = 30*MINUTE)),
    time_plot("5 days", serie(0, 120, HOUR)),
    time_plot("30 days", serie(0, 720, HOUR)),
    time_plot("-30..30 minutes", serie(-30, 30, MINUTE)),
    time_plot("-30..30 minutes + scale_y_time()", serie(-30, 30, MINUTE), y=True)
], ncol=2) + ggsize(960, 900)