├── tutorial
├── assets
│ ├── __init__.py
│ ├── bokeh-transparent.png
│ ├── 5_gaussians_3_ways.png
│ ├── 5_gaussians_dsblue.png
│ ├── 5_gaussians_labeled.png
│ ├── datashader_examples.png
│ └── document.svg
├── .gitignore
├── environment.yml
├── README.md
├── A4 - Additional Resources.ipynb
├── 11 - Running Bokeh Applictions.ipynb
├── 08 - Graph and Network Plots.ipynb
├── 09 - Geographic Plots.ipynb
└── 04 - Data Sources and Transformations.ipynb
├── quickstart
└── .gitignore
├── images
├── bokeh-header.png
└── bokeh-transparent.png
├── .gitignore
├── README.md
├── LICENSE.txt
└── index.ipynb
/tutorial/assets/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/quickstart/.gitignore:
--------------------------------------------------------------------------------
1 | barplot.html
2 |
--------------------------------------------------------------------------------
/tutorial/.gitignore:
--------------------------------------------------------------------------------
1 | plot.html
2 | plot.png
3 | plot.svg
4 |
--------------------------------------------------------------------------------
/images/bokeh-header.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DataXujing/bokeh-notebooks/master/images/bokeh-header.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .ipynb_checkpoints
2 | .ipynb_checkpoints/.
3 | .ipynb_checkpoints/
4 |
5 | .ropeproject
6 | __pycache__
7 |
--------------------------------------------------------------------------------
/images/bokeh-transparent.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DataXujing/bokeh-notebooks/master/images/bokeh-transparent.png
--------------------------------------------------------------------------------
/tutorial/assets/bokeh-transparent.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DataXujing/bokeh-notebooks/master/tutorial/assets/bokeh-transparent.png
--------------------------------------------------------------------------------
/tutorial/assets/5_gaussians_3_ways.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DataXujing/bokeh-notebooks/master/tutorial/assets/5_gaussians_3_ways.png
--------------------------------------------------------------------------------
/tutorial/assets/5_gaussians_dsblue.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DataXujing/bokeh-notebooks/master/tutorial/assets/5_gaussians_dsblue.png
--------------------------------------------------------------------------------
/tutorial/assets/5_gaussians_labeled.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DataXujing/bokeh-notebooks/master/tutorial/assets/5_gaussians_labeled.png
--------------------------------------------------------------------------------
/tutorial/assets/datashader_examples.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DataXujing/bokeh-notebooks/master/tutorial/assets/datashader_examples.png
--------------------------------------------------------------------------------
/tutorial/environment.yml:
--------------------------------------------------------------------------------
1 | name: bokeh-notebooks
2 | dependencies:
3 | - python
4 | - bokeh=0.12.2
5 | - pandas
6 | - jupyter
7 | - nodejs
8 | - ipywidgets
9 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Bokeh in Jupyter Notebooks
2 | ==========================
3 |
4 | Welcome to [Bokeh](https://bokeh.pydata.org/) in Jupyter Notebooks!
5 |
6 | Bokeh is a Python interactive visualization library for large datasets that
7 | natively uses the latest web technologies. Its goal is to provide elegant,
8 | concise construction of novel graphics in the style of Protovis/D3, while
9 | delivering high-performance interactivity over large data to thin clients.
10 |
11 | These Jupyter notebooks provide useful Bokeh examples and a tutorial to get
12 | started. You can visualize the rendered Jupyter notebooks
13 | [on NBViewer](http://nbviewer.ipython.org/github/bokeh/bokeh-notebooks) or
14 | download the repository and execute `jupyter notebook` from your terminal.
15 |
16 | Please visit the [Bokeh web page](https://bokeh.pydata.org/en/latest) for
17 | more information and full documentation.
18 |
19 | Be sure to follow us on Twitter @BokehPlots!
20 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Copyright (c) 2012, Continuum Analytics, Inc.
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without modification,
5 | are permitted provided that the following conditions are met:
6 |
7 | Redistributions of source code must retain the above copyright notice,
8 | this list of conditions and the following disclaimer.
9 |
10 | Redistributions in binary form must reproduce the above copyright notice,
11 | this list of conditions and the following disclaimer in the documentation
12 | and/or other materials provided with the distribution.
13 |
14 | Neither the name of Continuum Analytics nor the names of any contributors
15 | may be used to endorse or promote products derived from this software
16 | without specific prior written permission.
17 |
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28 | THE POSSIBILITY OF SUCH DAMAGE.
29 |
--------------------------------------------------------------------------------
/tutorial/README.md:
--------------------------------------------------------------------------------
1 | ## Clone or download the repo
2 | First get local copies of the tutorial notebooks:
3 |
4 | ```
5 | $ git clone https://github.com/bokeh/bokeh-notebooks.git
6 | ```
7 |
8 | Or download from: https://github.com/bokeh/bokeh-notebooks/archive/master.zip
9 |
10 | ## Install the dependencies
11 |
12 | This tutorial has been tested on:
13 |
14 | * bokeh 0.12.7
15 | * pandas 0.20.3
16 | * notebook 5.0.0
17 | * phantomjs 2.1.1
18 | * pillow 4.2.1
19 | * selenium 3.5.0
20 |
21 | Other combinations may work also.
22 |
23 | The quickest, easiest way to install is to use Anaconda (or Miniconda):
24 |
25 | #### Installing with anaconda
26 |
27 | Install [anaconda](http://anaconda.com/downloads)
28 |
29 | Anaconda should come with all the dependencies included, but you may need to update your versions.
30 |
31 | #### Installing with miniconda
32 |
33 | Install [miniconda](http://conda.pydata.org/miniconda.html).
34 |
35 | Use the command line to create an environment and install the packages:
36 |
37 | ```bash
38 | $ conda env create
39 | $ source activate bokeh-notebooks
40 | ```
41 |
42 | NOTE: Run this in the `tutorial` directory where `environment.yml` file is.
43 |
44 | ----
45 |
46 | Once you've got a base install, you can install the remaining dependencies with:
47 |
48 | ```bash
49 | conda install phantomjs pillow selenium
50 | ```
51 |
52 | ## Get the sample data
53 |
54 | Bokeh has a sample data download that gives us some data to build demo visualizations. To get
55 | it run the following command at your command line:
56 |
57 | ```bash
58 | $ bokeh sampledata
59 | ```
60 |
61 | ### Install Datashader and Holoviews (optional)
62 |
63 | Some optional sections require the additional packages Flask, Datashader, and Holoviews.
64 | These can be installed with:
65 |
66 | ```bash
67 | $ conda install -c datashader holoviews flask
68 | ```
69 |
70 | ## Run the Jupyter notebook
71 |
72 | From this folder run jupyter notebook, and open the [00 - Introduction and Setup.ipynb](00 - Introduction and Setup.ipynb) notebook.
73 |
74 | ```
75 | $ jupyter notebook
76 | ```
77 |
--------------------------------------------------------------------------------
/index.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "
\n",
8 | "\n",
9 | "
"
10 | ]
11 | },
12 | {
13 | "cell_type": "markdown",
14 | "metadata": {},
15 | "source": [
16 | "Welcome to [Bokeh](http://bokeh.pydata.org/en/latest) in the Jupyter Notebook!\n",
17 | "\n",
18 | "Bokeh is a Python interactive visualization library that targets modern web browsers for presentation. Its goal is to provide elegant, concise construction of novel graphics in the style of D3.js, and to extend this capability with high-performance interactivity over very large or streaming datasets. Bokeh can help anyone who would like to quickly and easily create interactive plots, dashboards, and data applications."
19 | ]
20 | },
21 | {
22 | "cell_type": "markdown",
23 | "metadata": {},
24 | "source": [
25 | "## Quickstart\n",
26 | "\n",
27 | "Get started with a [5-min introduction to Bokeh](quickstart/quickstart.ipynb)."
28 | ]
29 | },
30 | {
31 | "cell_type": "markdown",
32 | "metadata": {},
33 | "source": [
34 | "## Tutorial\n",
35 | "\n",
36 | "Start with the [Introduction and Setup](tutorial/00%20-%20Introduction%20and%20Setup.ipynb) notebook and jump to any of the specific topic sections from there."
37 | ]
38 | },
39 | {
40 | "cell_type": "markdown",
41 | "metadata": {},
42 | "source": [
43 | "## More information\n",
44 | "\n",
45 | "For the full documentation, see http://bokeh.pydata.org/en/latest\n",
46 | "\n",
47 | "To see the Bokeh source code, visit the GitHub repository: https://github.com/bokeh/bokeh \n",
48 | "\n",
49 | "Be sure to follow us on Twitter [@BokehPlots](http://twitter.com/BokehPlots) as well as on [Youtube](https://www.youtube.com/channel/UCK0rSk29mmg4UT4bIOvPYhw)!"
50 | ]
51 | },
52 | {
53 | "cell_type": "markdown",
54 | "metadata": {},
55 | "source": [
56 | "## Contact\n",
57 | "\n",
58 | "For questions, please join the [Bokeh mailing list](https://groups.google.com/a/anaconda.com/forum/#!forum/bokeh) or visit the [Gitter chat room](https://gitter.im/bokeh/bokeh)\n",
59 | "\n",
60 | "You can also ask questions on StackOverflow and use the [``#bokeh``](http://stackoverflow.com/questions/tagged/bokeh) tag.\n",
61 | "\n",
62 | "For information about commercial development, custom visualization development or embedding Bokeh in your applications, please contact [sales@anaconda.com](mailto:sales@anaconda.com)\n",
63 | "\n",
64 | "To donate funds to support the development of Bokeh, please contact [info@pydata.org](mailto:info@pydata.org)"
65 | ]
66 | },
67 | {
68 | "cell_type": "markdown",
69 | "metadata": {},
70 | "source": [
71 | "## Thanks\n",
72 | "\n",
73 | "Bokeh is developed with financial support from [Anaconda, Inc.](https://anaconda.com) as well as individual community contributions. Many thanks to [all of the Bokeh Github contributors](https://github.com/bokeh/bokeh/graphs/contributors)."
74 | ]
75 | },
76 | {
77 | "cell_type": "markdown",
78 | "metadata": {},
79 | "source": [
80 | ""
89 | ]
90 | }
91 | ],
92 | "metadata": {
93 | "kernelspec": {
94 | "display_name": "Python 3",
95 | "language": "python",
96 | "name": "python3"
97 | },
98 | "language_info": {
99 | "codemirror_mode": {
100 | "name": "ipython",
101 | "version": 3
102 | },
103 | "file_extension": ".py",
104 | "mimetype": "text/x-python",
105 | "name": "python",
106 | "nbconvert_exporter": "python",
107 | "pygments_lexer": "ipython3",
108 | "version": "3.6.2"
109 | }
110 | },
111 | "nbformat": 4,
112 | "nbformat_minor": 1
113 | }
114 |
--------------------------------------------------------------------------------
/tutorial/A4 - Additional Resources.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "
"
23 | ]
24 | },
25 | {
26 | "cell_type": "markdown",
27 | "metadata": {},
28 | "source": [
29 | "# Additional resources\n",
30 | "\n",
31 | "There are lots of things we haven't had time to tell you about. In general to learn more about bokeh, the following resources will hopefully be helpful:\n",
32 | "\n"
33 | ]
34 | },
35 | {
36 | "cell_type": "markdown",
37 | "metadata": {},
38 | "source": [
39 | "## Doumentation\n",
40 | "\n",
41 | "\n",
42 | "##### Main Page - https://bokeh.pydata.org/en/latest \n",
43 | "\n",
44 | "The main documentation front page, with links to many other resources\n",
45 | "\n",
46 | "---\n",
47 | "\n",
48 | "##### User's Guide - https://bokeh.pydata.org/en/latest/docs/user_guide.html\n",
49 | "\n",
50 | "The user's guide has many top-oriented subsections, for example \"Plotting with Basic Glyphs\", \"Configuring Plot Tools\", or \"Adding Interactions\". Each user's guide section typically example code and corresponding live plots that demonstrate how to accomplish various tasks. \n",
51 | "\n",
52 | "---\n",
53 | "\n",
54 | "##### Gallery - https://bokeh.pydata.org/en/latest/docs/gallery.html\n",
55 | "\n",
56 | "One of the best ways to learn is to find an existing example similar to what you want, and to study it and then use it as a starting place. Starting from a known working example can often save time and effort when getting started by allowing you to make small, incremental changes and observing the outcome. The Bokeh docs have a large thumbnail gallery that links to live plots and apps with corresponding code. \n",
57 | "\n",
58 | "\n",
59 | "---\n",
60 | "\n",
61 | "##### Reference Guide - https://bokeh.pydata.org/en/latest/docs/reference.html\n",
62 | "\n",
63 | "If you are already familiar with Bokeh and have questions about specific details of the obejcts you are already using, the reference guide is a good resource for finding information. The reference guide is automatically generated from the project source code and is a complete resources for all bokeh models and their properties. \n",
64 | "\n",
65 | "---\n",
66 | "\n",
67 | "##### Search page - https://bokeh.pydata.org/en/latest/search.html\n",
68 | "\n",
69 | "If you want to search the Bokeh docs, the search page on the site is the best place. General web searches can sometime return results for old versions or out of date information. The site search always returns information for the latest version, and results for any older versions in separate tabs. \n",
70 | "\n",
71 | "---\n",
72 | "\n",
73 | "##### Issue tracker - https://github.com/bokeh/bokeh/issues\n",
74 | "\n",
75 | "The GitHub issue tracker is the place to go to submit ***bug reports*** and ***feature requests***. It it NOT the right place for general support questions (see the *General Community Support* links below).\n",
76 | "\n"
77 | ]
78 | },
79 | {
80 | "cell_type": "markdown",
81 | "metadata": {
82 | "collapsed": true
83 | },
84 | "source": [
85 | "## Example apps and Scripts\n",
86 | "\n",
87 | "In addition to all the live gallery examples, Bokeh has many additional scripts and apps that can be instructive to study and emulate. \n",
88 | "\n",
89 | "##### Examples folder - https://github.com/bokeh/bokeh/tree/master/examples/\n",
90 | "\n",
91 | "The `examples` directory has many subfolders dedicated to different kinds of topics. Some of the hightlights are:\n",
92 | "\n",
93 | "* `app` - example Bokeh apps, run with \"`bokeh serve`\"\n",
94 | "* `howto` - some examples arranged around specific topics such as layout or notebook comms\n",
95 | "* `plotting` - a large collections of examples using the `bokeh.plotting` interface\n",
96 | "* `webgl` - some examples demonstrating WebGL usage\n",
97 | "\n",
98 | "---\n",
99 | "\n",
100 | "##### Example zipfile\n",
101 | "\n",
102 | "To make the things easier to obtain, a zip file of just the examples is also available at\n",
103 | "\n",
104 | "`https://cdn.pydata.org/bokeh/examples/examples-.zip`\n",
105 | "\n",
106 | "For example, the examples zipfile for the `0.12.7` release can be found at:\n",
107 | "\n",
108 | "https://cdn.pydata.org/bokeh/examples/examples-0.12.7.zip\n",
109 | "\n",
110 | "\n"
111 | ]
112 | },
113 | {
114 | "cell_type": "markdown",
115 | "metadata": {},
116 | "source": [
117 | "## General Commnity Support\n",
118 | "\n",
119 | "Bokeh has a large and growing community. The best place to go for general support questions (either to ask, or to answer!) is one of the community support resources listed below. \n",
120 | "\n",
121 | "* Mailing list - https://groups.google.com/a/anaconda.com/forum/#!forum/bokeh\n",
122 | "* Gitter chat channel - https://gitter.im/bokeh/bokeh\n",
123 | "* StackOverflow (use `#bokeh` tag): http://stackoverflow.com/questions/tagged/bokeh\n",
124 | "\n"
125 | ]
126 | },
127 | {
128 | "cell_type": "markdown",
129 | "metadata": {},
130 | "source": [
131 | "## Contributor Resources\n",
132 | "\n",
133 | "Bokeh has a small but growinf developer community. We are always looking to have new contributors. Below are some resources for people involved in working on Bokeh itself.\n",
134 | "\n",
135 | "##### Source code - https://github.com/bokeh/bokeh\n",
136 | "\n",
137 | "Go here to clone the GitHub repo (in order to contribute or get the examples), or to submit issues to the issue tracker \n",
138 | "\n",
139 | "---\n",
140 | "\n",
141 | "##### Issue tracker - https://github.com/bokeh/bokeh/issues\n",
142 | "\n",
143 | "The GitHub issue tracker is the place to go to submit ***bug reports*** and ***feature requests***. For general support questions, see the *General Community Support* links above.\n",
144 | "\n",
145 | "---\n",
146 | "\n",
147 | "#### Developer's Guide - https://bokeh.pydata.org/en/latest/docs/dev_guide.html\n",
148 | "\n",
149 | "If you are interesting in becoming a contributor to Bokeh, the developer's guide is the place to start. It has information about getting a development environment set up, the library architecture, writing and running tests, \n",
150 | "\n",
151 | "---\n",
152 | "\n",
153 | "#### Dev Chat Channel - https://gitter.im/bokeh/bokeh-dev\n",
154 | "\n",
155 | "Come here for assistance with any questions about developing Bokeh itself. \n"
156 | ]
157 | },
158 | {
159 | "cell_type": "code",
160 | "execution_count": null,
161 | "metadata": {
162 | "collapsed": true
163 | },
164 | "outputs": [],
165 | "source": []
166 | }
167 | ],
168 | "metadata": {
169 | "kernelspec": {
170 | "display_name": "Python 3",
171 | "language": "python",
172 | "name": "python3"
173 | },
174 | "language_info": {
175 | "codemirror_mode": {
176 | "name": "ipython",
177 | "version": 3
178 | },
179 | "file_extension": ".py",
180 | "mimetype": "text/x-python",
181 | "name": "python",
182 | "nbconvert_exporter": "python",
183 | "pygments_lexer": "ipython3",
184 | "version": "3.6.2"
185 | }
186 | },
187 | "nbformat": 4,
188 | "nbformat_minor": 1
189 | }
190 |
--------------------------------------------------------------------------------
/tutorial/11 - Running Bokeh Applictions.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "
"
24 | ]
25 | },
26 | {
27 | "cell_type": "markdown",
28 | "metadata": {},
29 | "source": [
30 | "The architecture of Bokeh is such that high-level “model objects” (representing things like plots, ranges, axes, glyphs, etc.) are created in Python, and then converted to a JSON format that is consumed by the client library, BokehJS. Using the Bokeh Server, it is possible to keep the “model objects” in python and in the browser in sync with one another, creating powerful capabilities:\n",
31 | "\n",
32 | "* respond to UI and tool events generated in a browser with computations or queries using the full power of python\n",
33 | "* automatically push updates the UI (i.e. widgets or plots), in a browser\n",
34 | "* use periodic, timeout, and asychronous callbacks drive streaming updates\n",
35 | "\n",
36 | "***This capability to synchronize between python and the browser is the main purpose of the Bokeh Server.***"
37 | ]
38 | },
39 | {
40 | "cell_type": "markdown",
41 | "metadata": {},
42 | "source": [
43 | "
NOTE: Exercises below require work outside the notebook
"
44 | ]
45 | },
46 | {
47 | "cell_type": "markdown",
48 | "metadata": {
49 | "collapsed": true
50 | },
51 | "source": [
52 | "# Hello Bokeh\n",
53 | "\n",
54 | "To try out the example below, copy the code into a file ``hello.py`` and then execute:\n",
55 | "```bash\n",
56 | "bokeh serve --show hello.py \n",
57 | "```\n",
58 | "----"
59 | ]
60 | },
61 | {
62 | "cell_type": "markdown",
63 | "metadata": {},
64 | "source": [
65 | "```python\n",
66 | "# hello.py \n",
67 | "\n",
68 | "from bokeh.io import curdoc\n",
69 | "from bokeh.layouts import column\n",
70 | "from bokeh.models.widgets import TextInput, Button, Paragraph\n",
71 | "\n",
72 | "# create some widgets\n",
73 | "button = Button(label=\"Say HI\")\n",
74 | "input = TextInput(value=\"Bokeh\")\n",
75 | "output = Paragraph()\n",
76 | "\n",
77 | "# add a callback to a widget\n",
78 | "def update():\n",
79 | " output.text = \"Hello, \" + input.value\n",
80 | "button.on_click(update)\n",
81 | "\n",
82 | "# create a layout for everything\n",
83 | "layout = column(button, input, output)\n",
84 | "\n",
85 | "# add the layout to curdoc\n",
86 | "curdoc().add_root(layout)\n",
87 | "```"
88 | ]
89 | },
90 | {
91 | "cell_type": "markdown",
92 | "metadata": {},
93 | "source": [
94 | "Let's try an exercise to modify this example to add another widget. "
95 | ]
96 | },
97 | {
98 | "cell_type": "code",
99 | "execution_count": 1,
100 | "metadata": {
101 | "collapsed": true
102 | },
103 | "outputs": [],
104 | "source": [
105 | "# EXERCISE: add a Select widget to this example that offers several different greetings\n",
106 | "\n"
107 | ]
108 | },
109 | {
110 | "cell_type": "markdown",
111 | "metadata": {},
112 | "source": [
113 | "# Linking Plots and Widgets\n",
114 | "\n",
115 | "To try out the example below, copy the code into a file ``app.py`` and then execute:\n",
116 | "```bash\n",
117 | "bokeh serve --show app.py\n",
118 | "```\n",
119 | "----"
120 | ]
121 | },
122 | {
123 | "cell_type": "markdown",
124 | "metadata": {},
125 | "source": [
126 | "```python\n",
127 | "# app.py\n",
128 | "\n",
129 | "from numpy.random import random\n",
130 | "\n",
131 | "from bokeh.io import curdoc\n",
132 | "from bokeh.layouts import column, row\n",
133 | "from bokeh.plotting import ColumnDataSource, Figure\n",
134 | "from bokeh.models.widgets import Select, TextInput\n",
135 | "\n",
136 | "def get_data(N):\n",
137 | " return dict(x=random(size=N), y=random(size=N), r=random(size=N) * 0.03)\n",
138 | "\n",
139 | "source = ColumnDataSource(data=get_data(200))\n",
140 | "\n",
141 | "p = Figure(tools=\"\", toolbar_location=None)\n",
142 | "r = p.circle(x='x', y='y', radius='r', source=source,\n",
143 | " color=\"navy\", alpha=0.6, line_color=\"white\")\n",
144 | "\n",
145 | "COLORS = [\"black\", \"firebrick\", \"navy\", \"olive\", \"goldenrod\"]\n",
146 | "select = Select(title=\"Color\", value=\"navy\", options=COLORS)\n",
147 | "input = TextInput(title=\"Number of points\", value=\"200\")\n",
148 | "\n",
149 | "def update_color(attrname, old, new):\n",
150 | " r.glyph.fill_color = select.value\n",
151 | "select.on_change('value', update_color)\n",
152 | "\n",
153 | "def update_points(attrname, old, new):\n",
154 | " N = int(input.value)\n",
155 | " source.data = get_data(N)\n",
156 | "input.on_change('value', update_points)\n",
157 | "\n",
158 | "layout = column(row(select, input, width=400), row(p))\n",
159 | "\n",
160 | "curdoc().add_root(layout)\n",
161 | "```"
162 | ]
163 | },
164 | {
165 | "cell_type": "code",
166 | "execution_count": 2,
167 | "metadata": {
168 | "collapsed": true
169 | },
170 | "outputs": [],
171 | "source": [
172 | "# EXERCISE: add more widgets to change more aspects of this plot\n"
173 | ]
174 | },
175 | {
176 | "cell_type": "markdown",
177 | "metadata": {},
178 | "source": [
179 | "# Streaming Data\n",
180 | "\n",
181 | "It is possible to efficiently stream new data to column data sources by using the ``stream`` method. This method accepts two argmuments:\n",
182 | "* ``new_data`` — a dictionary with the same structure as the column data source\n",
183 | "* ``rollover`` — a maximum column length on the client (earlier data is dropped) *[optional]*\n",
184 | "\n",
185 | "If no ``rollover`` is specified, data is never dropped on the client and columns grow without bound.\n",
186 | "\n",
187 | "It is often useful to use periodic callbacks in conjuction with streaming data The ``add_periodic_callback`` method of ``curdoc()`` accepts a callback function, and a time interval (in ms) to repeatedly execute the callback. \n",
188 | "\n",
189 | "To try out the example below, copy the code into a file ``stream.py`` and then execute:\n",
190 | "```bash\n",
191 | "bokeh serve --show stream.py\n",
192 | "```\n",
193 | "----"
194 | ]
195 | },
196 | {
197 | "cell_type": "markdown",
198 | "metadata": {},
199 | "source": [
200 | "```python\n",
201 | "# stream.py\n",
202 | "from math import cos, sin\n",
203 | "\n",
204 | "from bokeh.io import curdoc\n",
205 | "from bokeh.models import ColumnDataSource\n",
206 | "from bokeh.plotting import figure\n",
207 | "\n",
208 | "p = figure(x_range=(-1.1, 1.1), y_range=(-1.1, 1.1))\n",
209 | "p.circle(x=0, y=0, radius=1, fill_color=None, line_width=2)\n",
210 | "\n",
211 | "# this is the data source we will stream to\n",
212 | "source = ColumnDataSource(data=dict(x=[1], y=[0]))\n",
213 | "p.circle(x='x', y='y', size=12, fill_color='white', source=source)\n",
214 | "\n",
215 | "def update():\n",
216 | " x, y = source.data['x'][-1], source.data['y'][-1]\n",
217 | " \n",
218 | " # construct the new values for all columns, and pass to stream\n",
219 | " new_data = dict(x=[x*cos(0.1) - y*sin(0.1)], y=[x*sin(0.1) + y*cos(0.1)])\n",
220 | " source.stream(new_data, rollover=8)\n",
221 | "\n",
222 | "curdoc().add_periodic_callback(update, 150)\n",
223 | "curdoc().add_root(p)\n",
224 | "```"
225 | ]
226 | },
227 | {
228 | "cell_type": "code",
229 | "execution_count": 3,
230 | "metadata": {
231 | "collapsed": true
232 | },
233 | "outputs": [],
234 | "source": [
235 | "### EXERCISE: starting with the above example, create your own streaming plot\n"
236 | ]
237 | },
238 | {
239 | "cell_type": "code",
240 | "execution_count": null,
241 | "metadata": {
242 | "collapsed": true
243 | },
244 | "outputs": [],
245 | "source": []
246 | }
247 | ],
248 | "metadata": {
249 | "kernelspec": {
250 | "display_name": "Python 3",
251 | "language": "python",
252 | "name": "python3"
253 | },
254 | "language_info": {
255 | "codemirror_mode": {
256 | "name": "ipython",
257 | "version": 3
258 | },
259 | "file_extension": ".py",
260 | "mimetype": "text/x-python",
261 | "name": "python",
262 | "nbconvert_exporter": "python",
263 | "pygments_lexer": "ipython3",
264 | "version": "3.6.2"
265 | }
266 | },
267 | "nbformat": 4,
268 | "nbformat_minor": 1
269 | }
270 |
--------------------------------------------------------------------------------
/tutorial/assets/document.svg:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/tutorial/08 - Graph and Network Plots.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {
6 | "collapsed": true
7 | },
8 | "source": [
9 | "
\\n\"+\n",
72 | " \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n",
73 | " \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n",
74 | " \"
\\n\"+\n",
75 | " \"
\\n\"+\n",
76 | " \"
re-rerun `output_notebook()` to attempt to load from CDN again, or
\\n\"+\n",
70 | " \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n",
71 | " \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n",
72 | " \"
\\n\"+\n",
73 | " \"
\\n\"+\n",
74 | " \"
re-rerun `output_notebook()` to attempt to load from CDN again, or
\n",
270 | "\n"
285 | ],
286 | "text/plain": [
287 | "TileRenderer(id='25349dc1-ffc4-4ad6-97cc-7c8485687c40', ...)"
288 | ]
289 | },
290 | "execution_count": 3,
291 | "metadata": {},
292 | "output_type": "execute_result"
293 | }
294 | ],
295 | "source": [
296 | "url = 'http://a.basemaps.cartocdn.com/dark_all/{Z}/{X}/{Y}.png'\n",
297 | "attribution = \"Tiles by Carto, under CC BY 3.0. Data by OSM, under ODbL\"\n",
298 | "\n",
299 | "p.add_tile(WMTSTileSource(url=url, attribution=attribution))"
300 | ]
301 | },
302 | {
303 | "cell_type": "markdown",
304 | "metadata": {},
305 | "source": [
306 | "If you show the figure, you can then use the wheel zoom and pan tools to navigate over any zoom level, and Bokeh will request the appropriate tiles from the server and insert them at the correct locations in the plot:"
307 | ]
308 | },
309 | {
310 | "cell_type": "code",
311 | "execution_count": 4,
312 | "metadata": {},
313 | "outputs": [
314 | {
315 | "data": {
316 | "text/html": [
317 | "\n",
318 | "\n",
319 | "
\n",
320 | " \n",
321 | "
\n",
322 | ""
466 | ]
467 | },
468 | "metadata": {},
469 | "output_type": "display_data"
470 | }
471 | ],
472 | "source": [
473 | "show(p)"
474 | ]
475 | },
476 | {
477 | "cell_type": "markdown",
478 | "metadata": {},
479 | "source": [
480 | "That's all it takes to put map data into your plot! Of course, you'll usually want to show other data as well, or you could just use the tile server's own web address. You can now add anything you would normally use in a Bokeh plot, as long as you can obtain coordinates for it in Web Mercator format. For example:"
481 | ]
482 | },
483 | {
484 | "cell_type": "code",
485 | "execution_count": 5,
486 | "metadata": {},
487 | "outputs": [
488 | {
489 | "data": {
490 | "text/html": [
491 | "
\\n\"+\n",
82 | " \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n",
83 | " \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n",
84 | " \"
\\n\"+\n",
85 | " \"
\\n\"+\n",
86 | " \"
re-rerun `output_notebook()` to attempt to load from CDN again, or