Published
Edited
May 23, 2020
1 star
Insert cell
Insert cell
Insert cell
import {Bokeh} from "@jeremy9959/bokeh-experiments"
Insert cell
fruits = ["Apples", "Pears", "Nectarines", "Plums", "Grapes", "Strawberries"]

Insert cell
years = ["2015", "2016", "2017"]

Insert cell
// help the parser out by putting {} in ()
data = ({
2015: [2,1,4,1,2,3] ,
2016:[5,3,3,2,4,6],
2017: [ 3,2,4,4,5,3],
})
Insert cell
// loops need to be in little functions that return a value; this cells value is the result of the little program in the {}
x={
const x=[]
for (let fruit of fruits) {
for (let year of years) {
x.push([fruit,year])
}
}
return x
}
Insert cell
counts = Bokeh.LinAlg.concat(Bokeh.LinAlg.zip(data["2015"],data["2016"],data["2017"]))
Insert cell
P = {
var p = Bokeh.Plotting.figure({x_range: new Bokeh.FactorRange({factors: x, range_padding: 0.1}),
plot_height: 300, plot_width:800, toolbar_location: null, title: "Fruit Counts By Year"})
p.vbar({x, top: counts, width:0.9}) ;
p.xaxis.map((axis) => axis.major_label_orientation = 1) ;
p.xgrid.map((grid) => grid.grid_line_color = null) ;
p.y_range_start = 0 ;
return p ;
}
Insert cell
div = {
var div = html``
var doc = new Bokeh.Document() ;
doc.add_root(P) ;
await Bokeh.embed.add_document_standalone(doc, div)
return div ;
}
Insert cell
P
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more