Created
November 18, 2015 20:13
-
-
Save josePhoenix/9fc112ef88d6e545ef18 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 vform | |
| from bokeh.models import CustomJS, ColumnDataSource, Slider | |
| from bokeh.plotting import figure, output_file, show | |
| output_file("callback.html") | |
| orig_x, orig_y = np.arange(100), np.random.rand(100) | |
| x, y = orig_x.copy(), orig_y.copy() | |
| source_orig = ColumnDataSource(data=dict(x=orig_x, y=orig_y)) | |
| source = ColumnDataSource(data=dict(x=x, y=y)) | |
| plot = figure(plot_width=400, plot_height=400) | |
| plot.line('x', 'y', source=source, line_width=3, line_alpha=0.6) | |
| callback = CustomJS(args=dict(source=source, source_orig=source_orig), code=""" | |
| var orig_data = source_orig.get('data'); | |
| var data = source.get('data'); | |
| var f = cb_obj.get('value'); | |
| var orig_x = orig_data['x']; | |
| var orig_y = orig_data['y']; | |
| var new_x = []; | |
| var new_y = []; | |
| for (i = 0; i < orig_x.length; i++) { | |
| if (orig_x[i] > f) { | |
| new_x.push(orig_x[i]); | |
| new_y.push(orig_y[i]); | |
| } | |
| } | |
| data['x'] = new_x; | |
| data['y'] = new_y; | |
| source.trigger('change'); | |
| """) | |
| slider = Slider(start=0, end=100, value=1, step=1, title="minx", callback=callback) | |
| layout = vform(slider, plot) | |
| show(layout) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment