Skip to content

Bokeh example is incompatible with recent versions #4

@ostueker

Description

@ostueker

The Bokeh example in chapter 7 (Analysis and Visualization) on page 173 is no longer compatible with current versions of Bokeh.

Below is the corrected example and a diff compared with the content of cell [9] in ch08-analysis-and-viz.ipynb:

import numpy as np
# import the Bokeh plotting tools
from bokeh import plotting as bp

# as in the matplotlib example, load decays.csv into a NumPy array
decaydata = np.loadtxt('data/decays.csv',delimiter=",",skiprows=1)

# provide handles for the x and y columns
time = decaydata[:,0]
decays = decaydata[:,1]

# define some output file metadata
bp.output_file("decays.html", title="Experiment 1 Radioactivity")

# create a figure with fun Internet-friendly features (optional)
f = bp.figure(tools="pan,wheel_zoom,box_zoom,reset,previewsave",
              title="Decays", x_axis_label="Time (s)", y_axis_label="Decays (#)" )

# on that figure, create a line plot
f.line(time, decays, color='#1F78B4', legend='Decays per second' )

# additional customization to the figure can be specified separately
f.grid.grid_line_alpha=0.3

# open a browser
bp.show(f)
--- bokeh_old.py	2017-05-04 15:31:54.268924393 -0230
+++ bokeh_new.py	2017-05-04 15:31:02.076925327 -0230
@@ -13,15 +13,15 @@
 bp.output_file("decays.html", title="Experiment 1 Radioactivity")
 
 # create a figure with fun Internet-friendly features (optional)
-bp.figure(tools="pan,wheel_zoom,box_zoom,reset,previewsave")
+f = bp.figure(tools="pan,wheel_zoom,box_zoom,reset,previewsave",
+              title="Decays", x_axis_label="Time (s)", y_axis_label="Decays (#)" )
 
 # on that figure, create a line plot
-bp.line(time, decays, x_axis_label="Time (s)", y_axis_label="Decays (#)",
-     color='#1F78B4', legend='Decays per second')
+f.line(time, decays, color='#1F78B4', legend='Decays per second' )
 
 # additional customization to the figure can be specified separately
-bp.curplot().title = "Decays"
-bp.grid().grid_line_alpha=0.3
+f.grid.grid_line_alpha=0.3
 
 # open a browser
-bp.show()
+bp.show(f)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions