Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
from bokeh.embed import components
from bokeh.models import AjaxDataSource, Callback, Slider
from bokeh.plotting import figure, output_file, show, vplot
source = AjaxDataSource(
data_url='http://xxx.xxx.xxx.xxx:5000/subsample/0/180/0/360/350/800/0',
polling_interval=10000000,
data=dict(data=[[[0]]], x=[-180], dw=[360], y=[-90], dh=[180])
)
callback = Callback(args=dict(source=source), code="""
var t = slider.get('value')
var xr = plot.get('x_range')
var yr = plot.get('y_range')
lat_start = Math.max(yr.get('start'), -90) + 90
lat_end = Math.min(yr.get('end'), 90) + 90
lon_start = Math.max(xr.get('start'), -180) + 180
lon_end = Math.min(xr.get('end'), 180) + 180
var url = 'http://xxx.xxx.xxx.xxx:5000/subsample/' + +lat_start + '/' + lat_end + '/' + lon_start + '/' + lon_end + '/200/600/' + t
source.set('data_url', url, {'silent': true})
buffer = function(func, wait, scope) {
var timer = null;
return function() {
if(timer) clearTimeout(timer);
var args = arguments;
timer = setTimeout(function() { timer = null; func.apply(scope, args); }, wait);
};
};
buffer(source.get_data, 400)("replace")
""")
s = Slider(start=0, end=92, value=1, step=1, title="Time", callback=callback)
p = figure(plot_width=900, x_range=(-180, 180), y_range=(-90, 90))
p.image(image="data", x="x", y="y", dw="dw", dh="dh", palette="Spectral11", source=source)
p.x_range.callback = p.y_range.callback = callback
callback.args['plot'] = p
callback.args['slider'] = s
output_file("ocean.html")
show(vplot(s, p))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.