Bokeh inside SageMath 6.10 / Python 2

To see the published html, goto https://cloud.sagemath.com/20e4a191-73ea-4921-80e9-0a5d792fc511/raw/bokeh/bokeh-sage-6.10.html

In [1]:
import sys
sys.version
Out[1]:
'2.7.10 (default, Dec 28 2015, 04:30:58) \n[GCC 5.2.1 20151010]'
In [2]:
import numpy as np
print(np)
np.__version__
<module 'numpy' from '/projects/sage/sage-6.10/local/lib/python2.7/site-packages/numpy/__init__.pyc'>
Out[2]:
'1.10.1'
In [3]:
import bokeh
bokeh.__version__
Out[3]:
'0.10.0'
In [4]:
from bokeh.io import output_notebook, show
output_notebook()
/projects/sage/sage-6.10/local/lib/python2.7/site-packages/ndg/httpsclient/subj_alt_name.py:22: UserWarning: Error importing pyasn1, subjectAltName check for SSL peer verification will be disabled.  Import error is: No module named pyasn1.type
  warnings.warn(import_error_msg)
/projects/sage/sage-6.10/local/lib/python2.7/site-packages/ndg/httpsclient/ssl_peer_verification.py:25: UserWarning: SubjectAltName support is disabled - check pyasn1 package installation to enable
  warnings.warn(SUBJ_ALT_NAME_SUPPORT_MSG)
/projects/sage/sage-6.10/local/lib/python2.7/site-packages/ndg/httpsclient/subj_alt_name.py:22: UserWarning: Error importing pyasn1, subjectAltName check for SSL peer verification will be disabled.  Import error is: No module named pyasn1.type
  warnings.warn(import_error_msg)
BokehJS successfully loaded.
In [5]:
from bokeh.plotting import figure
import numpy as np

x = np.linspace(0, 4*np.pi, 100)
y = np.sin(x)


plot = figure(title="Sine Function")
plot.xaxis.axis_label='x'
plot.yaxis.axis_label='amplitude'


plot.line(x, y, 
  line_color='blue',
  line_width=2r,
  legend='sin(x)')

plot.circle(x, 2*y, 
  fill_color='red',
  line_color='black',
  fill_alpha=float(0.2),
  size=10r,
  legend='2sin(x)')

#line_dash is an aribrary length list of lengths
#alternating in [color, blank, color, ...]
plot.line(x, np.sin(2*x),
  line_color='green',
  line_dash=[10r,5r,2r,5r], 
  line_width=2r,
  legend='sin(2x)')

show(plot)
In [6]:
from bokeh.sampledata.iris import flowers
flowers.head()
Out[6]:
sepal_length sepal_width petal_length petal_width species
0 5.1 3.5 1.4 0.2 setosa
1 4.9 3.0 1.4 0.2 setosa
2 4.7 3.2 1.3 0.2 setosa
3 4.6 3.1 1.5 0.2 setosa
4 5.0 3.6 1.4 0.2 setosa
In [7]:
from bokeh.charts import Scatter

plot = Scatter(flowers, x='petal_length', y='petal_width',
               color='species',
               legend='top_left', title='Flower Morphology')
show(plot)
/projects/sage/sage-6.10/local/lib/python2.7/site-packages/bokeh/charts/_attributes.py:78: FutureWarning: sort(columns=....) is deprecated, use sort_values(by=.....)
  df = df.sort(columns=columns)
In [ ]: