from IPython.display import Image Image(url='http://i.imgur.com/h5GLIHc.gif') import pandas as pd import datetime from IPython.html import widgets from IPython.display import display, clear_output import plotly.plotly as py from plotly.graph_objs import * import plotly from plotly.widgets import GraphWidget df = pd.read_csv('https://raw.githubusercontent.com/plotly/widgets/master/ipython-examples/311_150k.csv', parse_dates=True, index_col=1) df = df df.head() grouped = df.resample('24H', how='count') slider = widgets.IntSliderWidget() slider.min = 1 slider.value=24 slider.description = 'Window length (hours)' column_headers_dropdown = widgets.DropdownWidget() column_headers_dropdown.values = {column: column for column in df.columns} column_headers_dropdown.value = 'Complaint Type' column_headers_dropdown.description = 'Select which column to graph (e.g. Tree)' search_complaints_text_input = widgets.TextWidget() search_complaints_text_input.description = 'Search complaint types' graph_time_series_agg = GraphWidget('https://plot.ly/~chris/4103') graph_time_series_agg.ranges = {'x': [1413648000000, 1416157200000], 'y': [0, 7744.210526315789]} graph_complaints = GraphWidget('https://plot.ly/~chris/4103') def replot(on_zoom=False): search_text = search_complaints_text_input.value slider_val = slider.value column_name = column_headers_dropdown.value # Time window that we're looking at ranges = graph_time_series_agg.ranges xr = ranges['x'] x1 = datetime.datetime.fromtimestamp(int(xr[0]/1000.)) x2 = datetime.datetime.fromtimestamp(int(xr[1]/1000.)) # Text value that we're looking at search_idx = df['Complaint Type'].str.contains(search_complaints_text_input.value).fillna(False) windowed_idx = search_idx & (df.index>x1) & (df.index