Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

interactive bokeh plots in cocalc

Views: 275
Image: ubuntu2004-dev
Kernel: Python 3 (system-wide)

Plotting with Bokeh on CoCalc

Ideas from https://docs.bokeh.org/en/latest/docs/user_guide/jupyter.html etc.

import bokeh bokeh.__version__
'2.2.3'
import numpy as np
from bokeh.io import show, output_notebook from bokeh.models import ColumnDataSource from bokeh.plotting import figure output_notebook()
Loading BokehJS ...
MIME type unknown not supported
p = figure(plot_width=700, plot_height=400) xx = np.linspace(-3 * np.pi, 3 * np.pi, 1000) yy = np.sin(xx**2) * np.log1p(np.abs(xx)) p.line(xx, yy, line_width=2) show(p)
MIME type unknown not supported
task_names = [ 'masonry', 'carpentry', 'plumbing', 'ceiling', 'roofing', 'painting', 'windows', 'facade', 'garden', 'moving' ] starts = [0, 35, 35, 35, 50, 50, 55, 75, 75, 85] ends = [35, 50, 75, 50, 55, 60, 60, 85, 80, 90] source = ColumnDataSource( data=dict(tasks=task_names, starts=starts, ends=ends)) p = figure(x_range=(0, 90), y_range=task_names, plot_height=350, title="Task Time Spans", toolbar_location=None, tools="") p.hbar(y='tasks', left='starts', right='ends', height=0.9, source=source) p.xaxis.axis_label = "Time" p.ygrid.grid_line_color = None show(p)
MIME type unknown not supported
from bokeh.layouts import gridplot from bokeh.plotting import figure, output_file, show x = np.linspace(0, 4*np.pi, 100) y = np.sin(x) TOOLS = "pan,wheel_zoom,box_zoom,reset,save,box_select" p1 = figure(title="Legend Example", tools=TOOLS) p1.circle(x, y, legend_label="sin(x)") p1.circle(x, 2*y, legend_label="2*sin(x)", color="orange") p1.circle(x, 3*y, legend_label="3*sin(x)", color="green") p1.legend.title = 'Example Title' p2 = figure(title="Another Legend Example", tools=TOOLS) p2.circle(x, y, legend_label="sin(x)") p2.line(x, y, legend_label="sin(x)") p2.line(x, 2*y, legend_label="2*sin(x)", line_dash=(4, 4), line_color="orange", line_width=2) p2.square(x, 3*y, legend_label="3*sin(x)", fill_color=None, line_color="green") p2.line(x, 3*y, legend_label="3*sin(x)", line_color="green") output_file("legend.html", title="legend.py example") show(gridplot([p1, p2], ncols=2, plot_width=400, plot_height=400))
MIME type unknown not supported