Created
January 31, 2018 00:40
-
-
Save ruoyu0088/ed2d77607767d67cd5185715bea5335f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from bokeh.io import show, output_notebook | |
from bokeh.plotting import figure | |
from bokeh import events | |
from bokeh.models import CustomJS, ColumnDataSource | |
output_notebook() | |
import pandas as pd | |
time1 = pd.date_range("2018/01/01", "2018/01/05", freq="h") | |
time2 = pd.date_range("2018/01/07", "2018/01/08", freq="h") | |
time = pd.concat([time1.to_series(), time2.to_series()]) | |
v = np.random.randn(len(time)) | |
df = pd.DataFrame({"value":v}, index=time) | |
loc = np.where((df.index[1:] - df.index[:-1]).total_seconds() > 10000)[0] | |
df2 = df.reindex(index=df.index.union(df.index[loc].shift(1, freq="s"))) | |
source = ColumnDataSource(data=dict(x=df2.index, y=df2["value"])) | |
fig = figure(plot_height=250, x_axis_type='datetime') | |
fig.line("x", "y", source=source) | |
show(fig) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment