9

Can someone give a short/simple example of how to plot a 2D-array with bokeh? Something similar to imshow() in matplotlib. I did not find a good examples given in the bokeh gallery.

a = np.array([[1,2], [3, 4]])
imshow(a)  # but with bokeh
Soerendip
  • 7,684
  • 15
  • 61
  • 128
  • 1
    That is what I am asking about. Code. I don't know any code that does that. That is the point. – Soerendip May 18 '18 at 23:37
  • Not sure why this was downvoted. Is https://bokeh.pydata.org/en/latest/docs/gallery/image.html what you want? –  May 18 '18 at 23:48

1 Answers1

7

Thanks Adian! That was a good direction. Here is a minimal example.

import numpy as np
from bokeh.plotting import figure, show

a = np.array([[1,2], [3, 4]])
p = figure(x_range=(0, 2), y_range=(0, 2))

# must give a vector of image data for image parameter
p.image(image=[a], x=0, y=0, dw=2, dh=2, palette="Spectral11")

show(p)
Soerendip
  • 7,684
  • 15
  • 61
  • 128