Bokeh Ray Glyph


In [1]:
from bokeh.plotting import figure, output_file, show
from bokeh.models import Range1d, ColumnDataSource
from bokeh.io import export_png
from math import pi
import numpy as np
import matplotlib.cm as cm
import pandas as pd

output_file("../../figures/ray.html")
num_lines = 51
source = pd.DataFrame(dict(
x = [0.5]*num_lines,
y = [0.5]*num_lines,
length = np.linspace(0.1,0.9,num_lines),
angle = np.linspace(0,4*pi,num_lines, endpoint=False)
))

cmap = cm.get_cmap('viridis')
source['colors'] = ["#%02x%02x%02x" % (int(r), int(g), int(b)) for r, g, b, a in 255*cmap(source['length'])]
source = ColumnDataSource(source) 

p = figure(plot_width=400, plot_height=400)
p.ray(x='x', y='y', length='length', angle='angle', source=source, line_cap='round',
         line_alpha=1, line_color='colors', line_dash='solid', line_width=5)
p.x_range = Range1d(-0.25, 1.25, bounds=(-1,2))
p.y_range = Range1d(-0.25, 1.25, bounds=(-1,2))
show(p)
export_png(p, filename="../../figures/ray.png");


---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
/usr/local/lib/python3.6/site-packages/bokeh/util/dependencies.py in import_required(mod_name, error_msg)
     49     try:
---> 50         return import_module(mod_name)
     51     except ImportError:

/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/importlib/__init__.py in import_module(name, package)
    125             level += 1
--> 126     return _bootstrap._gcd_import(name[level:], package, level)
    127 

/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/importlib/_bootstrap.py in _gcd_import(name, package, level)

/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/importlib/_bootstrap.py in _find_and_load(name, import_)

/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/importlib/_bootstrap.py in _find_and_load_unlocked(name, import_)

/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/importlib/_bootstrap.py in _call_with_frames_removed(f, *args, **kwds)

/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/importlib/_bootstrap.py in _gcd_import(name, package, level)

/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/importlib/_bootstrap.py in _find_and_load(name, import_)

/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/importlib/_bootstrap.py in _find_and_load_unlocked(name, import_)

ModuleNotFoundError: No module named 'selenium'

During handling of the above exception, another exception occurred:

RuntimeError                              Traceback (most recent call last)
<ipython-input-1-a5bedb3c20c2> in <module>()
     26 p.y_range = Range1d(-0.25, 1.25, bounds=(-1,2))
     27 show(p)
---> 28 export_png(p, filename="../../figures/ray.png");

/usr/local/lib/python3.6/site-packages/bokeh/io.py in export_png(obj, filename, height, width, webdriver)
    851     '''
    852 
--> 853     image = _get_screenshot_as_png(obj, height=height, width=width, driver=webdriver)
    854 
    855     if filename is None:

/usr/local/lib/python3.6/site-packages/bokeh/io.py in _get_screenshot_as_png(obj, driver, **kwargs)
    784     webdriver = import_required('selenium.webdriver',
    785                                 'To use bokeh.io.export_png you need selenium ' +
--> 786                                 '("conda install -c bokeh selenium" or "pip install selenium")')
    787 
    788     Image = import_required('PIL.Image',

/usr/local/lib/python3.6/site-packages/bokeh/util/dependencies.py in import_required(mod_name, error_msg)
     50         return import_module(mod_name)
     51     except ImportError:
---> 52         raise RuntimeError(error_msg)
     53 
     54 def detect_phantomjs():

RuntimeError: To use bokeh.io.export_png you need selenium ("conda install -c bokeh selenium" or "pip install selenium")