python - Smart x-axis for bokeh periodic time series -
i have time series data in pandas series object. values floats representing size of event. together, event times , sizes tell me how busy system is. i'm using scatterplot.
i want @ traffic patterns on various time periods, answer questions "is there daily spike @ noon?" or "which days of week have traffic?" therefore need overlay data many different periods. converting timestamps timedeltas (first subtracting start of first period, doing mod period length).
now index uses time intervals relative "abstract" time period, day or week. produce plots x-axis shows other nanoseconds. ideally show month, day of week, hour, etc. depending on timescale zoom in , out (as bokeh graphs time series).
the code below shows example of how plot. resulting graph has x-axis in units of nanoseconds, not want. how smart x-axis behaves more see timestamps?
import numpy np import pandas pd bokeh.charts import show, output_file bokeh.plotting import figure oneday = np.timedelta64(24*60*60,'s') fourhours = 24000000000000 # 4 hours in nanoseconds (ugly) time = [pd.timestamp('2015-04-27 01:00:00'), # monday pd.timestamp('2015-05-04 02:00:00'), # monday pd.timestamp('2015-05-11 03:00:00'), # monday pd.timestamp('2015-05-12 04:00:00') # tuesday ] resp = [2.0, 1.3, 2.6, 1.3] ts = pd.series(resp, index=time) days = dict(list(ts.groupby(lambda x: x.weekday))) monday = days[0] # timeseries consists of data mondays # convert timestamps timedeltas # first subtract timestamp of starting date # take remainder after dividing 1 day # result: each index value in 24 hour range [00:00:00, 23:59:59] tdi = monday.index - pd.timestamp(monday.index.date[0]) x = pd.timedeltaindex([td % oneday td in tdi]) y = monday.values output_file('bogus.html') xmax = fourhours # why doesn't np.timedelta64 work xmax? fig = figure(x_range=[0,xmax], y_range=[0,4]) fig.circle(x, y) show(fig)
Comments
Post a Comment