Skip to content

Instantly share code, notes, and snippets.

@lovit
Last active April 9, 2019 17:24
Show Gist options
  • Save lovit/6fcd33bc2963b5c2f748e16f9ac2c9dc to your computer and use it in GitHub Desktop.
Save lovit/6fcd33bc2963b5c2f748e16f9ac2c9dc to your computer and use it in GitHub Desktop.
Bokeh (1.0.4) image show example
# replace matplotlib.pyplot.imshow(img)
import numpy as np
from bokeh.plotting import figure, show, output_notebook
output_notebook()
N = 500
x = np.linspace(0, 10, N)
y = np.linspace(0, 10, N)
xx, yy = np.meshgrid(x, y)
d = np.sin(xx)*np.cos(yy) # (500, 500) numpy.ndarray
p = figure(x_range=(0, 10), y_range=(0, 10))
p.image(image=[d], x=0, y=0, dw=10, dh=10, palette="Spectral11") # uni channel with palette
show(p)
# figure size (10, 15) but image only (10, 10)
p = figure(x_range=(0, 10), y_range=(0, 15))
p.image(image=[d], x=0, y=0, dw=10, dh=10) # grey image
show(p)
@lovit
Copy link
Author

lovit commented Apr 9, 2019

Hover tool style

data = dict(
    image = [d],
    x = [0],
    y = [0],
    dw = [10],
    dh = [10]
)

TOOLTIPS = [
    ("x", "$x"),
    ("y", "$y"),
    ('dist', '@image'),
]

p = figure(x_range=(0, 10), y_range=(0, 10), tooltips=TOOLTIPS)
p.image(source=data, image='image', x='x', y='y', dw='dw', dh='dh', palette="Inferno256")
show(p)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment