Introduction to Bokeh for Plotting

First you need to import the Bokeh plotting package. We'll alias it to bk so save space and typing. Also import numpy so that we have tools for two-dimensional numerical arrays.


In [1]:
import numpy as np
import bokeh.plotting as bk
bk.output_notebook()


BokehJS successfully loaded.

Image example

First we create a simple data set using some trig functions to make two overlapping waves.


In [2]:
N = 500
x = np.linspace(-5.0, 5.0, N)
y = np.linspace(-5.0, 5.0, N)
xx,yy = np.meshgrid(x, y) # Expand x and y to 2D arrays
data = 1.0 * np.sin(6 * xx + 8 * yy) + 0.3 * np.cos(0.8 * xx - 0.2 * yy)

In [3]:
fig = bk.figure(x_range=[-5.0, 5.0], y_range=[-5.0, 5.0])
fig.image(image=[data], x=[-5], y=[-5], dw=[10], dh=[10], palette="YlOrBr9")
bk.show(fig)



In [ ]: