How to initialize a 2d image plot with Bokehjs

I’m trying to get an image plotting in bokehjs standalone, by loading in a 2d javascript array.

This shows it was possible in earlier versions of bokehjs. But now, if you switch out the lines to load bokeh 3.4.0, and use the same syntax for the ColumnDataSource and image() methods, the images don’t load.

Did something change about the figure.image() api?

Thanks,
Andrew

BokehJS stopped accepting ragged “lists of lists” as 2d arrays a very long time ago. You must use an actual array object with a dtype and a shape for multi-dimensional arrays inside a CDS.

AFAIK to create an array in BokehJS you can use the ndarray function from core/util/ndarray. Called something like this (a 1-d example, but to make it 2-d just adjust the shape appropriately):

ndarray(bins, {dtype: "float64", shape: [bins.length]})

But maybe @mateusz can comment in more detail.

Thanks. How would you create a basic 2d ndarray object with just Bokehjs?

With minified bokehjs loaded in the browser there’s no such thing like Bokeh.core.util.ndarray or Bokeh.ndarray

So far I’ve only found a hacky way of creating a 1d array using Bokeh.LinAlg.np.arange(0,100,2).

Thanks!

That’s a question for @mateusz. You might have better luck catching his attention in a GitHub development discussion.

1 Like