In [1]:
import numpy as np

In [10]:
from bokeh.plotting import figure, show, output_file, ColumnDataSource

In [3]:
from bokeh.models import HoverTool

In [4]:
x = np.linspace(0, 3.6*np.pi, 100)

In [5]:
y = np.abs(np.sin(x)/x)


/usr/local/lib/python3.5/dist-packages/ipykernel_launcher.py:1: RuntimeWarning: invalid value encountered in true_divide
  """Entry point for launching an IPython kernel.

In [6]:
output_file("bokeh_abs_sin.html")

p = figure(title='abs(sin(x)/x)')

cr = p.circle(x, y, size=20, fill_color="grey", hover_fill_color="firebrick",
                fill_alpha=0.05, hover_alpha=0.3,
                line_color=None, hover_line_color="white", legend="abs(sin(x)/x)")
p.line(x, y, legend="abs(sin(x)/x)", line_dash=[4, 4], line_color="firebrick", line_width=2)

p.legend.location = "top_right"

show(p)

In [7]:
p.legend.label_text_font = "times"
p.legend.label_text_font_style = "italic"
p.legend.label_text_color = "navy"
show(p)

In [8]:
p.add_tools(HoverTool(tooltips=None, renderers=[cr], mode='hline'))
show(p)

In [11]:
# transform the data in the data type specific to Bokeh: ColumnDataSource
source = ColumnDataSource(
    data=dict(
        xCDS=x,
        yCDS=y
    )
)

In [12]:
# customize the Hover tool
hover = HoverTool(tooltips = 
                  [("x:", "@x"),
                 ("y", "@y")])

In [13]:
p.add_tools(hover)

In [14]:
show(p)
  • Troubleshooting section:

In [3]:
# In case of missing Bokeh library:
!pip install bokeh


Collecting bokeh
  Downloading bokeh-0.12.10.tar.gz (15.7MB)
    100% |################################| 15.7MB 86kB/s 
Requirement already satisfied: six>=1.5.2 in /usr/lib/python3/dist-packages (from bokeh)
Requirement already satisfied: PyYAML>=3.10 in /usr/local/lib/python3.5/dist-packages (from bokeh)
Requirement already satisfied: python-dateutil>=2.1 in /usr/local/lib/python3.5/dist-packages (from bokeh)
Requirement already satisfied: Jinja2>=2.7 in /usr/local/lib/python3.5/dist-packages (from bokeh)
Requirement already satisfied: numpy>=1.7.1 in /usr/local/lib/python3.5/dist-packages (from bokeh)
Requirement already satisfied: tornado>=4.3 in /usr/local/lib/python3.5/dist-packages (from bokeh)
Requirement already satisfied: MarkupSafe>=0.23 in /usr/local/lib/python3.5/dist-packages (from Jinja2>=2.7->bokeh)
Building wheels for collected packages: bokeh
  Running setup.py bdist_wheel for bokeh ... - \ | / - done
  Stored in directory: /root/.cache/pip/wheels/80/14/83/a01ff14e74f69cd31122aeff20bc3f5a804f05fcb28bab365d
Successfully built bokeh
Installing collected packages: bokeh
Successfully installed bokeh-0.12.10

In [ ]: