Last active
August 29, 2015 14:01
-
-
Save iancze/3f5b1416ff5120e739cc to your computer and use it in GitHub Desktop.
Bokeh Embedding
This file contains 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>Test plot</title> | |
</head> | |
<body> | |
<div id="9fe4daf9-51ec-4a04-a625-d9d6c84217a9"> | |
<script | |
src="static/js/9fe4daf9-51ec-4a04-a625-d9d6c84217a9.js" | |
id="59f4cb89-3999-476e-b338-ec5f0b321d90" | |
async="true" | |
data-bokeh-data="static" | |
data-bokeh-modelid="9fe4daf9-51ec-4a04-a625-d9d6c84217a9" | |
data-bokeh-modeltype="Plot" | |
></script> | |
</div> | |
</body> | |
</html> |
This file contains 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
#!/usr/bin/env python | |
import numpy as np | |
import bokeh | |
import bokeh.plotting as bplt | |
from bokeh.resources import Resources | |
from bokeh.embed import autoload_static | |
def make_snippet(plot): | |
js_static_js = "static/js/" | |
js_static_css = "static/css/" | |
js_filename = plot._id + ".js" | |
js_path = js_static_js + js_filename | |
res = Resources("server") | |
res.js_files = [js_static_js + "bokeh.min.js"] | |
res.css_files = [js_static_css + "bokeh.min.css"] | |
js, tag = autoload_static(plot, res, js_path) | |
with open(js_path, "w") as f: | |
f.write(js) | |
print("Wrote %s" % js_path) | |
return tag, plot._id | |
#Generate random data | |
xs = np.linspace(0, 10, num=50) | |
ys = np.random.normal(size=(50,)) | |
bplt.output_file("image.html", title="Test Plot", mode="relative") | |
bplt.hold() | |
bplt.figure(title="Test Plot", | |
tools="pan,wheel_zoom,box_zoom,reset,previewsave,select", | |
plot_width=800, plot_height=300) | |
plot = bplt.line(xs , ys, line_width=1.5, legend="Random Data", color="blue") | |
tag1, id1 = make_snippet(plot) | |
with open("tag.txt", "w") as f: | |
f.write(tag1) | |
with open("id.txt", "w") as f: | |
f.write(id1) | |
bplt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment