├── .ipynb_checkpoints └── Untitled-checkpoint.ipynb ├── CONTRIBUTING.md ├── README.md ├── img ├── GSU_VYI1.png ├── GSU_VYI2.png ├── GSU_VYI3.png ├── QS_BPS.png ├── QS_GS1.png ├── QS_GS2.png ├── QS_ME_DA.png ├── QS_ME_LPB1.png ├── QS_ME_LPB2.png └── QS_ME_VCS.png ├── jupyter ├── .ipynb_checkpoints │ ├── QS-GS1-checkpoint.ipynb │ ├── QS-GS2-checkpoint.ipynb │ ├── QS-ME-LPB1-checkpoint.ipynb │ ├── QS-ME-LPB2-checkpoint.ipynb │ ├── QS-ME-VCS-checkpoint.ipynb │ └── QS_ME_DA-checkpoint.ipynb ├── QS-GS1.ipynb ├── QS-GS2.ipynb ├── QS-ME-LPB1.ipynb ├── QS-ME-LPB2.ipynb ├── QS-ME-VCS.ipynb └── QS_ME_DA.ipynb └── tmp ├── 一些重要概念(DonaldDai).md ├── 快速入门(DonaldDai).md ├── 插入图表或Apps(DonaldDai).md ├── 用基础标志绘图(DonaldDai).md ├── 用户指南(DonaldDai).md ├── 绘制高级图表(DonaldDai).md └── 设置(DonaldDai).md /.ipynb_checkpoints/Untitled-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [], 3 | "metadata": {}, 4 | "nbformat": 4, 5 | "nbformat_minor": 0 6 | } 7 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## 参与注意事项 2 | 3 | - 所有标题加上英文版标题,这样方便在引用图片和Jupyter Notebook例子更方便。格式如下 4 | 5 | ## 快速入门-Quickstart 6 | 7 | 8 | - 大标题以二级标题(**两个#**)显示,如 9 | 10 | ## 标题 11 | 12 | - 要翻译哪一部分请提前Issue或者E-mail我,先来后到哦~ 13 | 14 | - push的Markdown文档统一保存在`/tmp`路径下,命名格式为 15 | 16 | 大标题(你的ID) ------------------**括号为中文括号** 17 | 18 | 如 我翻译快速入门(Quickstart)可以保存为 19 | 20 | **快速入门(DonaldDai).md** 21 | 22 | `/tmp`中的文档我每天晚上0点会整合一次 23 | 24 | - 交互式图形截图统一保存在`/img`路径下,命名规则为 25 | 26 | 大标题选择简写\[_子标题选择简写\[顺序编号\]\] 27 | 28 | 如 在Qickstart_Linked panning and brushing下的两张图片可以保存为 29 | 30 | **QickStart_LinkedPanningandBrushing1.png**和**QickStart_LinkedPanningandBrushing2.png** 31 | 32 | 或者 33 | 34 | **QS_LPB1.png**和**QS_LPB2.png** 35 | 36 | - Jupyter notebook的例子保存在`/jupyter`路径下,命名规则跟图片一致,如果不会可以Email我哦 37 | 38 | - 参与者push的时间务必在**11:30**之前 39 | 40 | pull到本地的时间最好在**12:00**之后 41 | 42 | - 每次push请添加清晰的说明 43 | 44 | 比如 push的大概内容、更新了哪个名词的单词或者是通俗化了一些句子等 45 | 46 | 养成良好的说明习惯也方便日后自己查阅 -------------------------------------------------------------------------------- /img/GSU_VYI1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DonaldDai/Bokeh-CN/66e2183ae1ae10931c95bbbadedd3c0ff3d5e9b6/img/GSU_VYI1.png -------------------------------------------------------------------------------- /img/GSU_VYI2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DonaldDai/Bokeh-CN/66e2183ae1ae10931c95bbbadedd3c0ff3d5e9b6/img/GSU_VYI2.png -------------------------------------------------------------------------------- /img/GSU_VYI3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DonaldDai/Bokeh-CN/66e2183ae1ae10931c95bbbadedd3c0ff3d5e9b6/img/GSU_VYI3.png -------------------------------------------------------------------------------- /img/QS_BPS.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DonaldDai/Bokeh-CN/66e2183ae1ae10931c95bbbadedd3c0ff3d5e9b6/img/QS_BPS.png -------------------------------------------------------------------------------- /img/QS_GS1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DonaldDai/Bokeh-CN/66e2183ae1ae10931c95bbbadedd3c0ff3d5e9b6/img/QS_GS1.png -------------------------------------------------------------------------------- /img/QS_GS2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DonaldDai/Bokeh-CN/66e2183ae1ae10931c95bbbadedd3c0ff3d5e9b6/img/QS_GS2.png -------------------------------------------------------------------------------- /img/QS_ME_DA.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DonaldDai/Bokeh-CN/66e2183ae1ae10931c95bbbadedd3c0ff3d5e9b6/img/QS_ME_DA.png -------------------------------------------------------------------------------- /img/QS_ME_LPB1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DonaldDai/Bokeh-CN/66e2183ae1ae10931c95bbbadedd3c0ff3d5e9b6/img/QS_ME_LPB1.png -------------------------------------------------------------------------------- /img/QS_ME_LPB2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DonaldDai/Bokeh-CN/66e2183ae1ae10931c95bbbadedd3c0ff3d5e9b6/img/QS_ME_LPB2.png -------------------------------------------------------------------------------- /img/QS_ME_VCS.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DonaldDai/Bokeh-CN/66e2183ae1ae10931c95bbbadedd3c0ff3d5e9b6/img/QS_ME_VCS.png -------------------------------------------------------------------------------- /jupyter/.ipynb_checkpoints/QS-GS1-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": { 7 | "collapsed": false, 8 | "scrolled": true 9 | }, 10 | "outputs": [ 11 | { 12 | "data": { 13 | "text/html": [ 14 | "\n", 15 | "
\n", 16 | " \n", 17 | " Loading BokehJS ...\n", 18 | "
" 19 | ] 20 | }, 21 | "metadata": {}, 22 | "output_type": "display_data" 23 | }, 24 | { 25 | "data": { 26 | "application/javascript": [ 27 | "\n", 28 | "(function(global) {\n", 29 | " function now() {\n", 30 | " return new Date();\n", 31 | " }\n", 32 | "\n", 33 | " var force = \"1\";\n", 34 | "\n", 35 | " if (typeof (window._bokeh_onload_callbacks) === \"undefined\" || force !== \"\") {\n", 36 | " window._bokeh_onload_callbacks = [];\n", 37 | " window._bokeh_is_loading = undefined;\n", 38 | " }\n", 39 | "\n", 40 | " function run_callbacks() {\n", 41 | " window._bokeh_onload_callbacks.forEach(function(callback) { callback() });\n", 42 | " delete window._bokeh_onload_callbacks\n", 43 | " console.info(\"Bokeh: all callbacks have finished\");\n", 44 | " }\n", 45 | "\n", 46 | " function load_libs(js_urls, callback) {\n", 47 | " window._bokeh_onload_callbacks.push(callback);\n", 48 | " if (window._bokeh_is_loading > 0) {\n", 49 | " console.log(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n", 50 | " return null;\n", 51 | " }\n", 52 | " if (js_urls == null || js_urls.length === 0) {\n", 53 | " run_callbacks();\n", 54 | " return null;\n", 55 | " }\n", 56 | " console.log(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n", 57 | " window._bokeh_is_loading = js_urls.length;\n", 58 | " for (var i = 0; i < js_urls.length; i++) {\n", 59 | " var url = js_urls[i];\n", 60 | " var s = document.createElement('script');\n", 61 | " s.src = url;\n", 62 | " s.async = false;\n", 63 | " s.onreadystatechange = s.onload = function() {\n", 64 | " window._bokeh_is_loading--;\n", 65 | " if (window._bokeh_is_loading === 0) {\n", 66 | " console.log(\"Bokeh: all BokehJS libraries loaded\");\n", 67 | " run_callbacks()\n", 68 | " }\n", 69 | " };\n", 70 | " s.onerror = function() {\n", 71 | " console.warn(\"failed to load library \" + url);\n", 72 | " };\n", 73 | " console.log(\"Bokeh: injecting script tag for BokehJS library: \", url);\n", 74 | " document.getElementsByTagName(\"head\")[0].appendChild(s);\n", 75 | " }\n", 76 | " };\n", 77 | "\n", 78 | " var js_urls = ['https://cdn.pydata.org/bokeh/release/bokeh-0.12.1.min.js', 'https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.1.min.js', 'https://cdn.pydata.org/bokeh/release/bokeh-compiler-0.12.1.min.js'];\n", 79 | "\n", 80 | " var inline_js = [\n", 81 | " function(Bokeh) {\n", 82 | " Bokeh.set_log_level(\"info\");\n", 83 | " },\n", 84 | " \n", 85 | " function(Bokeh) {\n", 86 | " \n", 87 | " Bokeh.$(\"#d2d0945b-c6fd-4f4a-bb42-052f3e78a85c\").text(\"BokehJS successfully loaded\");\n", 88 | " var kernel = Jupyter.notebook.kernel\n", 89 | " if (kernel.execute !== undefined) {\n", 90 | " kernel.execute(\"import bokeh.io; bokeh.io._nb_loaded = True\");\n", 91 | " }\n", 92 | " },\n", 93 | " function(Bokeh) {\n", 94 | " console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-0.12.1.min.css\");\n", 95 | " Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-0.12.1.min.css\");\n", 96 | " console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.1.min.css\");\n", 97 | " Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.1.min.css\");\n", 98 | " }\n", 99 | " ];\n", 100 | "\n", 101 | " function run_inline_js() {\n", 102 | " for (var i = 0; i < inline_js.length; i++) {\n", 103 | " inline_js[i](window.Bokeh);\n", 104 | " }\n", 105 | " }\n", 106 | "\n", 107 | " if (window._bokeh_is_loading === 0) {\n", 108 | " console.log(\"Bokeh: BokehJS loaded, going straight to plotting\");\n", 109 | " run_inline_js();\n", 110 | " } else {\n", 111 | " load_libs(js_urls, function() {\n", 112 | " console.log(\"Bokeh: BokehJS plotting callback run at\", now());\n", 113 | " run_inline_js();\n", 114 | " });\n", 115 | " }\n", 116 | "}(this));" 117 | ] 118 | }, 119 | "metadata": {}, 120 | "output_type": "display_data" 121 | } 122 | ], 123 | "source": [ 124 | "from bokeh.plotting import figure, output_notebook, show\n", 125 | "\n", 126 | "# output to static HTML file\n", 127 | "output_notebook()" 128 | ] 129 | }, 130 | { 131 | "cell_type": "code", 132 | "execution_count": 2, 133 | "metadata": { 134 | "collapsed": false, 135 | "scrolled": false 136 | }, 137 | "outputs": [ 138 | { 139 | "data": { 140 | "text/html": [ 141 | "\n", 142 | "\n", 143 | "
\n", 144 | "
\n", 145 | "
\n", 146 | "" 234 | ] 235 | }, 236 | "metadata": {}, 237 | "output_type": "display_data" 238 | }, 239 | { 240 | "data": { 241 | "text/html": [ 242 | "

<Bokeh Notebook handle for In[2]>

" 243 | ], 244 | "text/plain": [ 245 | "" 246 | ] 247 | }, 248 | "execution_count": 2, 249 | "metadata": {}, 250 | "output_type": "execute_result" 251 | } 252 | ], 253 | "source": [ 254 | "# prepare some data\n", 255 | "x = [1, 2, 3, 4, 5]\n", 256 | "y = [6, 7, 2, 4, 5]\n", 257 | "\n", 258 | "# create a new plot with a title and axis labels\n", 259 | "p = figure(title=\"simple line example\", x_axis_label='x', y_axis_label='y')\n", 260 | "\n", 261 | "# add a line renderer with legend and line thickness\n", 262 | "p.line(x, y, legend=\"Temp.\", line_width=2)\n", 263 | "\n", 264 | "# show the results\n", 265 | "show(p)" 266 | ] 267 | }, 268 | { 269 | "cell_type": "code", 270 | "execution_count": null, 271 | "metadata": { 272 | "collapsed": true 273 | }, 274 | "outputs": [], 275 | "source": [] 276 | } 277 | ], 278 | "metadata": { 279 | "kernelspec": { 280 | "display_name": "Python 2", 281 | "language": "python", 282 | "name": "python2" 283 | }, 284 | "language_info": { 285 | "codemirror_mode": { 286 | "name": "ipython", 287 | "version": 2 288 | }, 289 | "file_extension": ".py", 290 | "mimetype": "text/x-python", 291 | "name": "python", 292 | "nbconvert_exporter": "python", 293 | "pygments_lexer": "ipython2", 294 | "version": "2.7.11" 295 | } 296 | }, 297 | "nbformat": 4, 298 | "nbformat_minor": 0 299 | } 300 | -------------------------------------------------------------------------------- /jupyter/.ipynb_checkpoints/QS-GS2-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": { 7 | "collapsed": false 8 | }, 9 | "outputs": [ 10 | { 11 | "data": { 12 | "text/html": [ 13 | "\n", 14 | "
\n", 15 | " \n", 16 | " Loading BokehJS ...\n", 17 | "
" 18 | ] 19 | }, 20 | "metadata": {}, 21 | "output_type": "display_data" 22 | }, 23 | { 24 | "data": { 25 | "application/javascript": [ 26 | "\n", 27 | "(function(global) {\n", 28 | " function now() {\n", 29 | " return new Date();\n", 30 | " }\n", 31 | "\n", 32 | " var force = \"1\";\n", 33 | "\n", 34 | " if (typeof (window._bokeh_onload_callbacks) === \"undefined\" || force !== \"\") {\n", 35 | " window._bokeh_onload_callbacks = [];\n", 36 | " window._bokeh_is_loading = undefined;\n", 37 | " }\n", 38 | "\n", 39 | " function run_callbacks() {\n", 40 | " window._bokeh_onload_callbacks.forEach(function(callback) { callback() });\n", 41 | " delete window._bokeh_onload_callbacks\n", 42 | " console.info(\"Bokeh: all callbacks have finished\");\n", 43 | " }\n", 44 | "\n", 45 | " function load_libs(js_urls, callback) {\n", 46 | " window._bokeh_onload_callbacks.push(callback);\n", 47 | " if (window._bokeh_is_loading > 0) {\n", 48 | " console.log(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n", 49 | " return null;\n", 50 | " }\n", 51 | " if (js_urls == null || js_urls.length === 0) {\n", 52 | " run_callbacks();\n", 53 | " return null;\n", 54 | " }\n", 55 | " console.log(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n", 56 | " window._bokeh_is_loading = js_urls.length;\n", 57 | " for (var i = 0; i < js_urls.length; i++) {\n", 58 | " var url = js_urls[i];\n", 59 | " var s = document.createElement('script');\n", 60 | " s.src = url;\n", 61 | " s.async = false;\n", 62 | " s.onreadystatechange = s.onload = function() {\n", 63 | " window._bokeh_is_loading--;\n", 64 | " if (window._bokeh_is_loading === 0) {\n", 65 | " console.log(\"Bokeh: all BokehJS libraries loaded\");\n", 66 | " run_callbacks()\n", 67 | " }\n", 68 | " };\n", 69 | " s.onerror = function() {\n", 70 | " console.warn(\"failed to load library \" + url);\n", 71 | " };\n", 72 | " console.log(\"Bokeh: injecting script tag for BokehJS library: \", url);\n", 73 | " document.getElementsByTagName(\"head\")[0].appendChild(s);\n", 74 | " }\n", 75 | " };\n", 76 | "\n", 77 | " var js_urls = ['https://cdn.pydata.org/bokeh/release/bokeh-0.12.1.min.js', 'https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.1.min.js', 'https://cdn.pydata.org/bokeh/release/bokeh-compiler-0.12.1.min.js'];\n", 78 | "\n", 79 | " var inline_js = [\n", 80 | " function(Bokeh) {\n", 81 | " Bokeh.set_log_level(\"info\");\n", 82 | " },\n", 83 | " \n", 84 | " function(Bokeh) {\n", 85 | " \n", 86 | " Bokeh.$(\"#456b555c-019c-4921-a674-b4edfe002aaf\").text(\"BokehJS successfully loaded\");\n", 87 | " var kernel = Jupyter.notebook.kernel\n", 88 | " if (kernel.execute !== undefined) {\n", 89 | " kernel.execute(\"import bokeh.io; bokeh.io._nb_loaded = True\");\n", 90 | " }\n", 91 | " },\n", 92 | " function(Bokeh) {\n", 93 | " console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-0.12.1.min.css\");\n", 94 | " Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-0.12.1.min.css\");\n", 95 | " console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.1.min.css\");\n", 96 | " Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.1.min.css\");\n", 97 | " }\n", 98 | " ];\n", 99 | "\n", 100 | " function run_inline_js() {\n", 101 | " for (var i = 0; i < inline_js.length; i++) {\n", 102 | " inline_js[i](window.Bokeh);\n", 103 | " }\n", 104 | " }\n", 105 | "\n", 106 | " if (window._bokeh_is_loading === 0) {\n", 107 | " console.log(\"Bokeh: BokehJS loaded, going straight to plotting\");\n", 108 | " run_inline_js();\n", 109 | " } else {\n", 110 | " load_libs(js_urls, function() {\n", 111 | " console.log(\"Bokeh: BokehJS plotting callback run at\", now());\n", 112 | " run_inline_js();\n", 113 | " });\n", 114 | " }\n", 115 | "}(this));" 116 | ] 117 | }, 118 | "metadata": {}, 119 | "output_type": "display_data" 120 | } 121 | ], 122 | "source": [ 123 | "from bokeh.plotting import figure, output_notebook, show\n", 124 | "\n", 125 | "# output to static HTML file\n", 126 | "output_notebook()" 127 | ] 128 | }, 129 | { 130 | "cell_type": "code", 131 | "execution_count": 2, 132 | "metadata": { 133 | "collapsed": false 134 | }, 135 | "outputs": [ 136 | { 137 | "data": { 138 | "text/html": [ 139 | "\n", 140 | "\n", 141 | "
\n", 142 | "
\n", 143 | "
\n", 144 | "" 232 | ] 233 | }, 234 | "metadata": {}, 235 | "output_type": "display_data" 236 | }, 237 | { 238 | "data": { 239 | "text/html": [ 240 | "

<Bokeh Notebook handle for In[2]>

" 241 | ], 242 | "text/plain": [ 243 | "" 244 | ] 245 | }, 246 | "execution_count": 2, 247 | "metadata": {}, 248 | "output_type": "execute_result" 249 | } 250 | ], 251 | "source": [ 252 | "# prepare some data\n", 253 | "x = [0.1, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0]\n", 254 | "y0 = [i**2 for i in x]\n", 255 | "y1 = [10**i for i in x]\n", 256 | "y2 = [10**(i**2) for i in x]\n", 257 | "\n", 258 | "# create a new plot\n", 259 | "p = figure(\n", 260 | " tools=\"pan,box_zoom,reset,save\",\n", 261 | " y_axis_type=\"log\", y_range=[0.001, 10**11], title=\"log axis example\",\n", 262 | " x_axis_label='sections', y_axis_label='particles'\n", 263 | ")\n", 264 | "\n", 265 | "# add some renderers\n", 266 | "p.line(x, x, legend=\"y=x\")\n", 267 | "p.circle(x, x, legend=\"y=x\", fill_color=\"white\", size=8)\n", 268 | "p.line(x, y0, legend=\"y=x^2\", line_width=3)\n", 269 | "p.line(x, y1, legend=\"y=10^x\", line_color=\"red\")\n", 270 | "p.circle(x, y1, legend=\"y=10^x\", fill_color=\"red\", line_color=\"red\", size=6)\n", 271 | "p.line(x, y2, legend=\"y=10^x^2\", line_color=\"orange\", line_dash=\"4 4\")\n", 272 | "\n", 273 | "# show the results\n", 274 | "show(p)" 275 | ] 276 | }, 277 | { 278 | "cell_type": "code", 279 | "execution_count": null, 280 | "metadata": { 281 | "collapsed": true 282 | }, 283 | "outputs": [], 284 | "source": [] 285 | } 286 | ], 287 | "metadata": { 288 | "kernelspec": { 289 | "display_name": "Python 2", 290 | "language": "python", 291 | "name": "python2" 292 | }, 293 | "language_info": { 294 | "codemirror_mode": { 295 | "name": "ipython", 296 | "version": 2 297 | }, 298 | "file_extension": ".py", 299 | "mimetype": "text/x-python", 300 | "name": "python", 301 | "nbconvert_exporter": "python", 302 | "pygments_lexer": "ipython2", 303 | "version": "2.7.11" 304 | } 305 | }, 306 | "nbformat": 4, 307 | "nbformat_minor": 0 308 | } 309 | -------------------------------------------------------------------------------- /jupyter/.ipynb_checkpoints/QS-ME-LPB1-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 2, 6 | "metadata": { 7 | "collapsed": false 8 | }, 9 | "outputs": [ 10 | { 11 | "data": { 12 | "text/html": [ 13 | "\n", 14 | "
\n", 15 | " \n", 16 | " Loading BokehJS ...\n", 17 | "
" 18 | ] 19 | }, 20 | "metadata": {}, 21 | "output_type": "display_data" 22 | }, 23 | { 24 | "data": { 25 | "application/javascript": [ 26 | "\n", 27 | "(function(global) {\n", 28 | " function now() {\n", 29 | " return new Date();\n", 30 | " }\n", 31 | "\n", 32 | " var force = \"1\";\n", 33 | "\n", 34 | " if (typeof (window._bokeh_onload_callbacks) === \"undefined\" || force !== \"\") {\n", 35 | " window._bokeh_onload_callbacks = [];\n", 36 | " window._bokeh_is_loading = undefined;\n", 37 | " }\n", 38 | "\n", 39 | " function run_callbacks() {\n", 40 | " window._bokeh_onload_callbacks.forEach(function(callback) { callback() });\n", 41 | " delete window._bokeh_onload_callbacks\n", 42 | " console.info(\"Bokeh: all callbacks have finished\");\n", 43 | " }\n", 44 | "\n", 45 | " function load_libs(js_urls, callback) {\n", 46 | " window._bokeh_onload_callbacks.push(callback);\n", 47 | " if (window._bokeh_is_loading > 0) {\n", 48 | " console.log(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n", 49 | " return null;\n", 50 | " }\n", 51 | " if (js_urls == null || js_urls.length === 0) {\n", 52 | " run_callbacks();\n", 53 | " return null;\n", 54 | " }\n", 55 | " console.log(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n", 56 | " window._bokeh_is_loading = js_urls.length;\n", 57 | " for (var i = 0; i < js_urls.length; i++) {\n", 58 | " var url = js_urls[i];\n", 59 | " var s = document.createElement('script');\n", 60 | " s.src = url;\n", 61 | " s.async = false;\n", 62 | " s.onreadystatechange = s.onload = function() {\n", 63 | " window._bokeh_is_loading--;\n", 64 | " if (window._bokeh_is_loading === 0) {\n", 65 | " console.log(\"Bokeh: all BokehJS libraries loaded\");\n", 66 | " run_callbacks()\n", 67 | " }\n", 68 | " };\n", 69 | " s.onerror = function() {\n", 70 | " console.warn(\"failed to load library \" + url);\n", 71 | " };\n", 72 | " console.log(\"Bokeh: injecting script tag for BokehJS library: \", url);\n", 73 | " document.getElementsByTagName(\"head\")[0].appendChild(s);\n", 74 | " }\n", 75 | " };\n", 76 | "\n", 77 | " var js_urls = ['https://cdn.pydata.org/bokeh/release/bokeh-0.12.1.min.js', 'https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.1.min.js', 'https://cdn.pydata.org/bokeh/release/bokeh-compiler-0.12.1.min.js'];\n", 78 | "\n", 79 | " var inline_js = [\n", 80 | " function(Bokeh) {\n", 81 | " Bokeh.set_log_level(\"info\");\n", 82 | " },\n", 83 | " \n", 84 | " function(Bokeh) {\n", 85 | " \n", 86 | " Bokeh.$(\"#301998ae-1c19-48c5-92a9-7ca6df965aca\").text(\"BokehJS successfully loaded\");\n", 87 | " var kernel = Jupyter.notebook.kernel\n", 88 | " if (kernel.execute !== undefined) {\n", 89 | " kernel.execute(\"import bokeh.io; bokeh.io._nb_loaded = True\");\n", 90 | " }\n", 91 | " },\n", 92 | " function(Bokeh) {\n", 93 | " console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-0.12.1.min.css\");\n", 94 | " Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-0.12.1.min.css\");\n", 95 | " console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.1.min.css\");\n", 96 | " Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.1.min.css\");\n", 97 | " }\n", 98 | " ];\n", 99 | "\n", 100 | " function run_inline_js() {\n", 101 | " for (var i = 0; i < inline_js.length; i++) {\n", 102 | " inline_js[i](window.Bokeh);\n", 103 | " }\n", 104 | " }\n", 105 | "\n", 106 | " if (window._bokeh_is_loading === 0) {\n", 107 | " console.log(\"Bokeh: BokehJS loaded, going straight to plotting\");\n", 108 | " run_inline_js();\n", 109 | " } else {\n", 110 | " load_libs(js_urls, function() {\n", 111 | " console.log(\"Bokeh: BokehJS plotting callback run at\", now());\n", 112 | " run_inline_js();\n", 113 | " });\n", 114 | " }\n", 115 | "}(this));" 116 | ] 117 | }, 118 | "metadata": {}, 119 | "output_type": "display_data" 120 | } 121 | ], 122 | "source": [ 123 | "import numpy as np\n", 124 | "\n", 125 | "from bokeh.layouts import gridplot\n", 126 | "from bokeh.plotting import figure, output_notebook, show\n", 127 | "\n", 128 | "# output to static HTML file\n", 129 | "output_notebook()" 130 | ] 131 | }, 132 | { 133 | "cell_type": "code", 134 | "execution_count": 3, 135 | "metadata": { 136 | "collapsed": false 137 | }, 138 | "outputs": [ 139 | { 140 | "data": { 141 | "text/html": [ 142 | "\n", 143 | "\n", 144 | "
\n", 145 | "
\n", 146 | "
\n", 147 | "" 235 | ] 236 | }, 237 | "metadata": {}, 238 | "output_type": "display_data" 239 | }, 240 | { 241 | "data": { 242 | "text/html": [ 243 | "

<Bokeh Notebook handle for In[3]>

" 244 | ], 245 | "text/plain": [ 246 | "" 247 | ] 248 | }, 249 | "execution_count": 3, 250 | "metadata": {}, 251 | "output_type": "execute_result" 252 | } 253 | ], 254 | "source": [ 255 | "# prepare some data\n", 256 | "N = 100\n", 257 | "x = np.linspace(0, 4*np.pi, N)\n", 258 | "y0 = np.sin(x)\n", 259 | "y1 = np.cos(x)\n", 260 | "y2 = np.sin(x) + np.cos(x)\n", 261 | "\n", 262 | "# create a new plot\n", 263 | "s1 = figure(width=250, plot_height=250, title=None)\n", 264 | "s1.circle(x, y0, size=10, color=\"navy\", alpha=0.5)\n", 265 | "\n", 266 | "# NEW: create a new plot and share both ranges\n", 267 | "s2 = figure(width=250, height=250, x_range=s1.x_range, y_range=s1.y_range, title=None)\n", 268 | "s2.triangle(x, y1, size=10, color=\"firebrick\", alpha=0.5)\n", 269 | "\n", 270 | "# NEW: create a new plot and share only one range\n", 271 | "s3 = figure(width=250, height=250, x_range=s1.x_range, title=None)\n", 272 | "s3.square(x, y2, size=10, color=\"olive\", alpha=0.5)\n", 273 | "\n", 274 | "# NEW: put the subplots in a gridplot\n", 275 | "p = gridplot([[s1, s2, s3]], toolbar_location=None)\n", 276 | "\n", 277 | "# show the results\n", 278 | "show(p)" 279 | ] 280 | }, 281 | { 282 | "cell_type": "code", 283 | "execution_count": null, 284 | "metadata": { 285 | "collapsed": true 286 | }, 287 | "outputs": [], 288 | "source": [] 289 | } 290 | ], 291 | "metadata": { 292 | "kernelspec": { 293 | "display_name": "Python 2", 294 | "language": "python", 295 | "name": "python2" 296 | }, 297 | "language_info": { 298 | "codemirror_mode": { 299 | "name": "ipython", 300 | "version": 2 301 | }, 302 | "file_extension": ".py", 303 | "mimetype": "text/x-python", 304 | "name": "python", 305 | "nbconvert_exporter": "python", 306 | "pygments_lexer": "ipython2", 307 | "version": "2.7.11" 308 | } 309 | }, 310 | "nbformat": 4, 311 | "nbformat_minor": 0 312 | } 313 | -------------------------------------------------------------------------------- /jupyter/QS-GS1.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": { 7 | "collapsed": false, 8 | "scrolled": true 9 | }, 10 | "outputs": [ 11 | { 12 | "data": { 13 | "text/html": [ 14 | "\n", 15 | "
\n", 16 | " \n", 17 | " Loading BokehJS ...\n", 18 | "
" 19 | ] 20 | }, 21 | "metadata": {}, 22 | "output_type": "display_data" 23 | }, 24 | { 25 | "data": { 26 | "application/javascript": [ 27 | "\n", 28 | "(function(global) {\n", 29 | " function now() {\n", 30 | " return new Date();\n", 31 | " }\n", 32 | "\n", 33 | " var force = \"1\";\n", 34 | "\n", 35 | " if (typeof (window._bokeh_onload_callbacks) === \"undefined\" || force !== \"\") {\n", 36 | " window._bokeh_onload_callbacks = [];\n", 37 | " window._bokeh_is_loading = undefined;\n", 38 | " }\n", 39 | "\n", 40 | " function run_callbacks() {\n", 41 | " window._bokeh_onload_callbacks.forEach(function(callback) { callback() });\n", 42 | " delete window._bokeh_onload_callbacks\n", 43 | " console.info(\"Bokeh: all callbacks have finished\");\n", 44 | " }\n", 45 | "\n", 46 | " function load_libs(js_urls, callback) {\n", 47 | " window._bokeh_onload_callbacks.push(callback);\n", 48 | " if (window._bokeh_is_loading > 0) {\n", 49 | " console.log(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n", 50 | " return null;\n", 51 | " }\n", 52 | " if (js_urls == null || js_urls.length === 0) {\n", 53 | " run_callbacks();\n", 54 | " return null;\n", 55 | " }\n", 56 | " console.log(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n", 57 | " window._bokeh_is_loading = js_urls.length;\n", 58 | " for (var i = 0; i < js_urls.length; i++) {\n", 59 | " var url = js_urls[i];\n", 60 | " var s = document.createElement('script');\n", 61 | " s.src = url;\n", 62 | " s.async = false;\n", 63 | " s.onreadystatechange = s.onload = function() {\n", 64 | " window._bokeh_is_loading--;\n", 65 | " if (window._bokeh_is_loading === 0) {\n", 66 | " console.log(\"Bokeh: all BokehJS libraries loaded\");\n", 67 | " run_callbacks()\n", 68 | " }\n", 69 | " };\n", 70 | " s.onerror = function() {\n", 71 | " console.warn(\"failed to load library \" + url);\n", 72 | " };\n", 73 | " console.log(\"Bokeh: injecting script tag for BokehJS library: \", url);\n", 74 | " document.getElementsByTagName(\"head\")[0].appendChild(s);\n", 75 | " }\n", 76 | " };\n", 77 | "\n", 78 | " var js_urls = ['https://cdn.pydata.org/bokeh/release/bokeh-0.12.1.min.js', 'https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.1.min.js', 'https://cdn.pydata.org/bokeh/release/bokeh-compiler-0.12.1.min.js'];\n", 79 | "\n", 80 | " var inline_js = [\n", 81 | " function(Bokeh) {\n", 82 | " Bokeh.set_log_level(\"info\");\n", 83 | " },\n", 84 | " \n", 85 | " function(Bokeh) {\n", 86 | " \n", 87 | " Bokeh.$(\"#d2d0945b-c6fd-4f4a-bb42-052f3e78a85c\").text(\"BokehJS successfully loaded\");\n", 88 | " var kernel = Jupyter.notebook.kernel\n", 89 | " if (kernel.execute !== undefined) {\n", 90 | " kernel.execute(\"import bokeh.io; bokeh.io._nb_loaded = True\");\n", 91 | " }\n", 92 | " },\n", 93 | " function(Bokeh) {\n", 94 | " console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-0.12.1.min.css\");\n", 95 | " Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-0.12.1.min.css\");\n", 96 | " console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.1.min.css\");\n", 97 | " Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.1.min.css\");\n", 98 | " }\n", 99 | " ];\n", 100 | "\n", 101 | " function run_inline_js() {\n", 102 | " for (var i = 0; i < inline_js.length; i++) {\n", 103 | " inline_js[i](window.Bokeh);\n", 104 | " }\n", 105 | " }\n", 106 | "\n", 107 | " if (window._bokeh_is_loading === 0) {\n", 108 | " console.log(\"Bokeh: BokehJS loaded, going straight to plotting\");\n", 109 | " run_inline_js();\n", 110 | " } else {\n", 111 | " load_libs(js_urls, function() {\n", 112 | " console.log(\"Bokeh: BokehJS plotting callback run at\", now());\n", 113 | " run_inline_js();\n", 114 | " });\n", 115 | " }\n", 116 | "}(this));" 117 | ] 118 | }, 119 | "metadata": {}, 120 | "output_type": "display_data" 121 | } 122 | ], 123 | "source": [ 124 | "from bokeh.plotting import figure, output_notebook, show\n", 125 | "\n", 126 | "# output to static HTML file\n", 127 | "output_notebook()" 128 | ] 129 | }, 130 | { 131 | "cell_type": "code", 132 | "execution_count": 2, 133 | "metadata": { 134 | "collapsed": false, 135 | "scrolled": false 136 | }, 137 | "outputs": [ 138 | { 139 | "data": { 140 | "text/html": [ 141 | "\n", 142 | "\n", 143 | "
\n", 144 | "
\n", 145 | "
\n", 146 | "" 234 | ] 235 | }, 236 | "metadata": {}, 237 | "output_type": "display_data" 238 | }, 239 | { 240 | "data": { 241 | "text/html": [ 242 | "

<Bokeh Notebook handle for In[2]>

" 243 | ], 244 | "text/plain": [ 245 | "" 246 | ] 247 | }, 248 | "execution_count": 2, 249 | "metadata": {}, 250 | "output_type": "execute_result" 251 | } 252 | ], 253 | "source": [ 254 | "# prepare some data\n", 255 | "x = [1, 2, 3, 4, 5]\n", 256 | "y = [6, 7, 2, 4, 5]\n", 257 | "\n", 258 | "# create a new plot with a title and axis labels\n", 259 | "p = figure(title=\"simple line example\", x_axis_label='x', y_axis_label='y')\n", 260 | "\n", 261 | "# add a line renderer with legend and line thickness\n", 262 | "p.line(x, y, legend=\"Temp.\", line_width=2)\n", 263 | "\n", 264 | "# show the results\n", 265 | "show(p)" 266 | ] 267 | }, 268 | { 269 | "cell_type": "code", 270 | "execution_count": null, 271 | "metadata": { 272 | "collapsed": true 273 | }, 274 | "outputs": [], 275 | "source": [] 276 | } 277 | ], 278 | "metadata": { 279 | "kernelspec": { 280 | "display_name": "Python 2", 281 | "language": "python", 282 | "name": "python2" 283 | }, 284 | "language_info": { 285 | "codemirror_mode": { 286 | "name": "ipython", 287 | "version": 2 288 | }, 289 | "file_extension": ".py", 290 | "mimetype": "text/x-python", 291 | "name": "python", 292 | "nbconvert_exporter": "python", 293 | "pygments_lexer": "ipython2", 294 | "version": "2.7.11" 295 | } 296 | }, 297 | "nbformat": 4, 298 | "nbformat_minor": 0 299 | } 300 | -------------------------------------------------------------------------------- /jupyter/QS-GS2.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": { 7 | "collapsed": false 8 | }, 9 | "outputs": [ 10 | { 11 | "data": { 12 | "text/html": [ 13 | "\n", 14 | "
\n", 15 | " \n", 16 | " Loading BokehJS ...\n", 17 | "
" 18 | ] 19 | }, 20 | "metadata": {}, 21 | "output_type": "display_data" 22 | }, 23 | { 24 | "data": { 25 | "application/javascript": [ 26 | "\n", 27 | "(function(global) {\n", 28 | " function now() {\n", 29 | " return new Date();\n", 30 | " }\n", 31 | "\n", 32 | " var force = \"1\";\n", 33 | "\n", 34 | " if (typeof (window._bokeh_onload_callbacks) === \"undefined\" || force !== \"\") {\n", 35 | " window._bokeh_onload_callbacks = [];\n", 36 | " window._bokeh_is_loading = undefined;\n", 37 | " }\n", 38 | "\n", 39 | " function run_callbacks() {\n", 40 | " window._bokeh_onload_callbacks.forEach(function(callback) { callback() });\n", 41 | " delete window._bokeh_onload_callbacks\n", 42 | " console.info(\"Bokeh: all callbacks have finished\");\n", 43 | " }\n", 44 | "\n", 45 | " function load_libs(js_urls, callback) {\n", 46 | " window._bokeh_onload_callbacks.push(callback);\n", 47 | " if (window._bokeh_is_loading > 0) {\n", 48 | " console.log(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n", 49 | " return null;\n", 50 | " }\n", 51 | " if (js_urls == null || js_urls.length === 0) {\n", 52 | " run_callbacks();\n", 53 | " return null;\n", 54 | " }\n", 55 | " console.log(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n", 56 | " window._bokeh_is_loading = js_urls.length;\n", 57 | " for (var i = 0; i < js_urls.length; i++) {\n", 58 | " var url = js_urls[i];\n", 59 | " var s = document.createElement('script');\n", 60 | " s.src = url;\n", 61 | " s.async = false;\n", 62 | " s.onreadystatechange = s.onload = function() {\n", 63 | " window._bokeh_is_loading--;\n", 64 | " if (window._bokeh_is_loading === 0) {\n", 65 | " console.log(\"Bokeh: all BokehJS libraries loaded\");\n", 66 | " run_callbacks()\n", 67 | " }\n", 68 | " };\n", 69 | " s.onerror = function() {\n", 70 | " console.warn(\"failed to load library \" + url);\n", 71 | " };\n", 72 | " console.log(\"Bokeh: injecting script tag for BokehJS library: \", url);\n", 73 | " document.getElementsByTagName(\"head\")[0].appendChild(s);\n", 74 | " }\n", 75 | " };\n", 76 | "\n", 77 | " var js_urls = ['https://cdn.pydata.org/bokeh/release/bokeh-0.12.1.min.js', 'https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.1.min.js', 'https://cdn.pydata.org/bokeh/release/bokeh-compiler-0.12.1.min.js'];\n", 78 | "\n", 79 | " var inline_js = [\n", 80 | " function(Bokeh) {\n", 81 | " Bokeh.set_log_level(\"info\");\n", 82 | " },\n", 83 | " \n", 84 | " function(Bokeh) {\n", 85 | " \n", 86 | " Bokeh.$(\"#456b555c-019c-4921-a674-b4edfe002aaf\").text(\"BokehJS successfully loaded\");\n", 87 | " var kernel = Jupyter.notebook.kernel\n", 88 | " if (kernel.execute !== undefined) {\n", 89 | " kernel.execute(\"import bokeh.io; bokeh.io._nb_loaded = True\");\n", 90 | " }\n", 91 | " },\n", 92 | " function(Bokeh) {\n", 93 | " console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-0.12.1.min.css\");\n", 94 | " Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-0.12.1.min.css\");\n", 95 | " console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.1.min.css\");\n", 96 | " Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.1.min.css\");\n", 97 | " }\n", 98 | " ];\n", 99 | "\n", 100 | " function run_inline_js() {\n", 101 | " for (var i = 0; i < inline_js.length; i++) {\n", 102 | " inline_js[i](window.Bokeh);\n", 103 | " }\n", 104 | " }\n", 105 | "\n", 106 | " if (window._bokeh_is_loading === 0) {\n", 107 | " console.log(\"Bokeh: BokehJS loaded, going straight to plotting\");\n", 108 | " run_inline_js();\n", 109 | " } else {\n", 110 | " load_libs(js_urls, function() {\n", 111 | " console.log(\"Bokeh: BokehJS plotting callback run at\", now());\n", 112 | " run_inline_js();\n", 113 | " });\n", 114 | " }\n", 115 | "}(this));" 116 | ] 117 | }, 118 | "metadata": {}, 119 | "output_type": "display_data" 120 | } 121 | ], 122 | "source": [ 123 | "from bokeh.plotting import figure, output_notebook, show\n", 124 | "\n", 125 | "# output to static HTML file\n", 126 | "output_notebook()" 127 | ] 128 | }, 129 | { 130 | "cell_type": "code", 131 | "execution_count": 2, 132 | "metadata": { 133 | "collapsed": false 134 | }, 135 | "outputs": [ 136 | { 137 | "data": { 138 | "text/html": [ 139 | "\n", 140 | "\n", 141 | "
\n", 142 | "
\n", 143 | "
\n", 144 | "" 232 | ] 233 | }, 234 | "metadata": {}, 235 | "output_type": "display_data" 236 | }, 237 | { 238 | "data": { 239 | "text/html": [ 240 | "

<Bokeh Notebook handle for In[2]>

" 241 | ], 242 | "text/plain": [ 243 | "" 244 | ] 245 | }, 246 | "execution_count": 2, 247 | "metadata": {}, 248 | "output_type": "execute_result" 249 | } 250 | ], 251 | "source": [ 252 | "# prepare some data\n", 253 | "x = [0.1, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0]\n", 254 | "y0 = [i**2 for i in x]\n", 255 | "y1 = [10**i for i in x]\n", 256 | "y2 = [10**(i**2) for i in x]\n", 257 | "\n", 258 | "# create a new plot\n", 259 | "p = figure(\n", 260 | " tools=\"pan,box_zoom,reset,save\",\n", 261 | " y_axis_type=\"log\", y_range=[0.001, 10**11], title=\"log axis example\",\n", 262 | " x_axis_label='sections', y_axis_label='particles'\n", 263 | ")\n", 264 | "\n", 265 | "# add some renderers\n", 266 | "p.line(x, x, legend=\"y=x\")\n", 267 | "p.circle(x, x, legend=\"y=x\", fill_color=\"white\", size=8)\n", 268 | "p.line(x, y0, legend=\"y=x^2\", line_width=3)\n", 269 | "p.line(x, y1, legend=\"y=10^x\", line_color=\"red\")\n", 270 | "p.circle(x, y1, legend=\"y=10^x\", fill_color=\"red\", line_color=\"red\", size=6)\n", 271 | "p.line(x, y2, legend=\"y=10^x^2\", line_color=\"orange\", line_dash=\"4 4\")\n", 272 | "\n", 273 | "# show the results\n", 274 | "show(p)" 275 | ] 276 | }, 277 | { 278 | "cell_type": "code", 279 | "execution_count": null, 280 | "metadata": { 281 | "collapsed": true 282 | }, 283 | "outputs": [], 284 | "source": [] 285 | } 286 | ], 287 | "metadata": { 288 | "kernelspec": { 289 | "display_name": "Python 2", 290 | "language": "python", 291 | "name": "python2" 292 | }, 293 | "language_info": { 294 | "codemirror_mode": { 295 | "name": "ipython", 296 | "version": 2 297 | }, 298 | "file_extension": ".py", 299 | "mimetype": "text/x-python", 300 | "name": "python", 301 | "nbconvert_exporter": "python", 302 | "pygments_lexer": "ipython2", 303 | "version": "2.7.11" 304 | } 305 | }, 306 | "nbformat": 4, 307 | "nbformat_minor": 0 308 | } 309 | -------------------------------------------------------------------------------- /jupyter/QS-ME-LPB1.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 2, 6 | "metadata": { 7 | "collapsed": false 8 | }, 9 | "outputs": [ 10 | { 11 | "data": { 12 | "text/html": [ 13 | "\n", 14 | "
\n", 15 | " \n", 16 | " Loading BokehJS ...\n", 17 | "
" 18 | ] 19 | }, 20 | "metadata": {}, 21 | "output_type": "display_data" 22 | }, 23 | { 24 | "data": { 25 | "application/javascript": [ 26 | "\n", 27 | "(function(global) {\n", 28 | " function now() {\n", 29 | " return new Date();\n", 30 | " }\n", 31 | "\n", 32 | " var force = \"1\";\n", 33 | "\n", 34 | " if (typeof (window._bokeh_onload_callbacks) === \"undefined\" || force !== \"\") {\n", 35 | " window._bokeh_onload_callbacks = [];\n", 36 | " window._bokeh_is_loading = undefined;\n", 37 | " }\n", 38 | "\n", 39 | " function run_callbacks() {\n", 40 | " window._bokeh_onload_callbacks.forEach(function(callback) { callback() });\n", 41 | " delete window._bokeh_onload_callbacks\n", 42 | " console.info(\"Bokeh: all callbacks have finished\");\n", 43 | " }\n", 44 | "\n", 45 | " function load_libs(js_urls, callback) {\n", 46 | " window._bokeh_onload_callbacks.push(callback);\n", 47 | " if (window._bokeh_is_loading > 0) {\n", 48 | " console.log(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n", 49 | " return null;\n", 50 | " }\n", 51 | " if (js_urls == null || js_urls.length === 0) {\n", 52 | " run_callbacks();\n", 53 | " return null;\n", 54 | " }\n", 55 | " console.log(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n", 56 | " window._bokeh_is_loading = js_urls.length;\n", 57 | " for (var i = 0; i < js_urls.length; i++) {\n", 58 | " var url = js_urls[i];\n", 59 | " var s = document.createElement('script');\n", 60 | " s.src = url;\n", 61 | " s.async = false;\n", 62 | " s.onreadystatechange = s.onload = function() {\n", 63 | " window._bokeh_is_loading--;\n", 64 | " if (window._bokeh_is_loading === 0) {\n", 65 | " console.log(\"Bokeh: all BokehJS libraries loaded\");\n", 66 | " run_callbacks()\n", 67 | " }\n", 68 | " };\n", 69 | " s.onerror = function() {\n", 70 | " console.warn(\"failed to load library \" + url);\n", 71 | " };\n", 72 | " console.log(\"Bokeh: injecting script tag for BokehJS library: \", url);\n", 73 | " document.getElementsByTagName(\"head\")[0].appendChild(s);\n", 74 | " }\n", 75 | " };\n", 76 | "\n", 77 | " var js_urls = ['https://cdn.pydata.org/bokeh/release/bokeh-0.12.1.min.js', 'https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.1.min.js', 'https://cdn.pydata.org/bokeh/release/bokeh-compiler-0.12.1.min.js'];\n", 78 | "\n", 79 | " var inline_js = [\n", 80 | " function(Bokeh) {\n", 81 | " Bokeh.set_log_level(\"info\");\n", 82 | " },\n", 83 | " \n", 84 | " function(Bokeh) {\n", 85 | " \n", 86 | " Bokeh.$(\"#301998ae-1c19-48c5-92a9-7ca6df965aca\").text(\"BokehJS successfully loaded\");\n", 87 | " var kernel = Jupyter.notebook.kernel\n", 88 | " if (kernel.execute !== undefined) {\n", 89 | " kernel.execute(\"import bokeh.io; bokeh.io._nb_loaded = True\");\n", 90 | " }\n", 91 | " },\n", 92 | " function(Bokeh) {\n", 93 | " console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-0.12.1.min.css\");\n", 94 | " Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-0.12.1.min.css\");\n", 95 | " console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.1.min.css\");\n", 96 | " Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.1.min.css\");\n", 97 | " }\n", 98 | " ];\n", 99 | "\n", 100 | " function run_inline_js() {\n", 101 | " for (var i = 0; i < inline_js.length; i++) {\n", 102 | " inline_js[i](window.Bokeh);\n", 103 | " }\n", 104 | " }\n", 105 | "\n", 106 | " if (window._bokeh_is_loading === 0) {\n", 107 | " console.log(\"Bokeh: BokehJS loaded, going straight to plotting\");\n", 108 | " run_inline_js();\n", 109 | " } else {\n", 110 | " load_libs(js_urls, function() {\n", 111 | " console.log(\"Bokeh: BokehJS plotting callback run at\", now());\n", 112 | " run_inline_js();\n", 113 | " });\n", 114 | " }\n", 115 | "}(this));" 116 | ] 117 | }, 118 | "metadata": {}, 119 | "output_type": "display_data" 120 | } 121 | ], 122 | "source": [ 123 | "import numpy as np\n", 124 | "\n", 125 | "from bokeh.layouts import gridplot\n", 126 | "from bokeh.plotting import figure, output_notebook, show\n", 127 | "\n", 128 | "# output to static HTML file\n", 129 | "output_notebook()" 130 | ] 131 | }, 132 | { 133 | "cell_type": "code", 134 | "execution_count": 3, 135 | "metadata": { 136 | "collapsed": false 137 | }, 138 | "outputs": [ 139 | { 140 | "data": { 141 | "text/html": [ 142 | "\n", 143 | "\n", 144 | "
\n", 145 | "
\n", 146 | "
\n", 147 | "" 235 | ] 236 | }, 237 | "metadata": {}, 238 | "output_type": "display_data" 239 | }, 240 | { 241 | "data": { 242 | "text/html": [ 243 | "

<Bokeh Notebook handle for In[3]>

" 244 | ], 245 | "text/plain": [ 246 | "" 247 | ] 248 | }, 249 | "execution_count": 3, 250 | "metadata": {}, 251 | "output_type": "execute_result" 252 | } 253 | ], 254 | "source": [ 255 | "# prepare some data\n", 256 | "N = 100\n", 257 | "x = np.linspace(0, 4*np.pi, N)\n", 258 | "y0 = np.sin(x)\n", 259 | "y1 = np.cos(x)\n", 260 | "y2 = np.sin(x) + np.cos(x)\n", 261 | "\n", 262 | "# create a new plot\n", 263 | "s1 = figure(width=250, plot_height=250, title=None)\n", 264 | "s1.circle(x, y0, size=10, color=\"navy\", alpha=0.5)\n", 265 | "\n", 266 | "# NEW: create a new plot and share both ranges\n", 267 | "s2 = figure(width=250, height=250, x_range=s1.x_range, y_range=s1.y_range, title=None)\n", 268 | "s2.triangle(x, y1, size=10, color=\"firebrick\", alpha=0.5)\n", 269 | "\n", 270 | "# NEW: create a new plot and share only one range\n", 271 | "s3 = figure(width=250, height=250, x_range=s1.x_range, title=None)\n", 272 | "s3.square(x, y2, size=10, color=\"olive\", alpha=0.5)\n", 273 | "\n", 274 | "# NEW: put the subplots in a gridplot\n", 275 | "p = gridplot([[s1, s2, s3]], toolbar_location=None)\n", 276 | "\n", 277 | "# show the results\n", 278 | "show(p)" 279 | ] 280 | }, 281 | { 282 | "cell_type": "code", 283 | "execution_count": null, 284 | "metadata": { 285 | "collapsed": true 286 | }, 287 | "outputs": [], 288 | "source": [] 289 | } 290 | ], 291 | "metadata": { 292 | "kernelspec": { 293 | "display_name": "Python 2", 294 | "language": "python", 295 | "name": "python2" 296 | }, 297 | "language_info": { 298 | "codemirror_mode": { 299 | "name": "ipython", 300 | "version": 2 301 | }, 302 | "file_extension": ".py", 303 | "mimetype": "text/x-python", 304 | "name": "python", 305 | "nbconvert_exporter": "python", 306 | "pygments_lexer": "ipython2", 307 | "version": "2.7.11" 308 | } 309 | }, 310 | "nbformat": 4, 311 | "nbformat_minor": 0 312 | } 313 | -------------------------------------------------------------------------------- /tmp/一些重要概念(DonaldDai).md: -------------------------------------------------------------------------------- 1 | ## 一些重要概念-Defining Key Concepts 2 | 3 | ### 术语表-Glossary 4 | 5 | 为了更好的使用用户指南,了解相关高级概念很重要。下面是一份小术语表,上面介绍了一些Bokeh的重要概念 6 | 7 | ------ 8 | 9 | **应用** 10 | 11 | Bokeh应用指的是一个已经渲染过的文件,结果一般运行在浏览器中。 12 | 13 | **BokehJS文件** 14 | 15 | Bokeh的Javascript文件主要用于渲染图形和UI中的交互工具。一般用户不需要考虑JavaScript文件中的内容,但如果你知道一些关于JavaScript和Bokeh之间的联系的知识,那最好不过啦。更多细节可以查看[开发者指南](http://bokeh.pydata.org/en/latest/docs/dev_guide.html#devguide)中的[BokehJS](http://bokeh.pydata.org/en/latest/docs/dev_guide/bokehjs.html#devguide-bokehjs)。 16 | 17 | **图表** 18 | 19 | 示例中的静态图如柱状图,水平延伸的图和时间序列图等都可以由Bokeh提供的`bokeh.charts`高级接口来快速构建。更多示例及用法请查看 [构建高级图表](http://bokeh.pydata.org/en/latest/docs/user_guide/charts.html#userguide-charts)。 20 | 21 | **文件** 22 | 23 | 文件指的是Bokeh应用所使用的数据集。文件中包含Bokeh应用渲染图表和交互工具所要用到的所有模型和数据。 24 | 25 | **嵌入** 26 | 27 | 嵌入指的是在Web应用、网页或者Jupyter(Ipython) Notebook中插入Bokeh的图标。更多细节请查看 [插入图表或Apps](http://bokeh.pydata.org/en/latest/docs/user_guide/embed.html#userguide-embed)。 28 | 29 | **标志** 30 | 31 | 标志是构建Bokeh图形的基础元素,如曲线、三角形、方形、楔形、图示等都属于标志。`bokeh.plotting`接口提供了便捷的方法创建自定义标志。更多细节请查看 [Plotting with Basic Glyphs](http://bokeh.pydata.org/en/latest/docs/user_guide/plotting.html#userguide-plotting)。 32 | 33 | **模型** 34 | 35 | 模型是Bokeh中最底层的类,模型的作用就是组成Bokeh应用的整个“轮廓(scenegraphs)”。这些类在`bokeh.models`接口里。大多数的用户不会直接接触到这些底层的类。然而最终的Bokeh应用是由这些类的集合组成的,所以理解它也是非常重要的,这样你可以更随心所欲的绘制Bokeh图形。更多信息请查看[Styling Visual Attributes](http://bokeh.pydata.org/en/latest/docs/user_guide/styling.html#userguide-styling)。 36 | 37 | **Bokeh服务器** 38 | 39 | Bokeh服务器是一个可选项,即使不使用Bokeh可以在浏览器中渲染交互图形。Bokeh服务器主要用于发布或分享交流Bokeh图形或者应用,它的特点是可以处理大型流数据集。更多信息请查看[Running a Bokeh Server](http://bokeh.pydata.org/en/latest/docs/user_guide/server.html#userguide-server)。 40 | 41 | **挂件** 42 | 43 | 挂件指的是在图形外围的那些元素。如滚动条、下拉式菜单、按钮等都属于挂件。与挂件交互会出发后台的一些函数,从而影响图形中的数据。挂件可以用在独立的Bokeh应用中也可以搭配Bokeh服务器一起使用。更多信息请查看[Adding Interactions](http://bokeh.pydata.org/en/latest/docs/user_guide/interaction.html#userguide-interaction)。 44 | 45 | ----- 46 | 47 | ### 输出方式-Output Methods 48 | 49 | 我们可以看到用户指南中遍布的示例中有很多输出文件的方式,最常用的主要是以下几种: 50 | 51 | **output_file** 52 | 53 | 用于生成独立的Bokeh图表HTML文件。 54 | 55 | **output_notebook** 56 | 57 | 用于在Jupyter notebook上嵌入Bokeh图形 58 | 59 | **output_server** 60 | 61 | 用于在一个运行着的Bokeh服务器安装Bokeh应用 62 | 63 | 这些函数经常回合`show`或者`save`搭配使用。这里是一个例子 64 | 65 | ```python 66 | from bokeh.plotting import figure, output_file, show 67 | 68 | output_file("output.html") 69 | 70 | p = figure() 71 | p.line(x=[1, 2, 3], y=[4,6,2]) 72 | 73 | show(p) 74 | ``` 75 | 76 | Well,假设这个文件叫`foopy`,那么执行`python foo.py`会生成一个包含Bokeh图形的HTML文件。这些函数搭配在交互式设置和从Web应用(如Flask、Django等)中分离出单独的HTML图形文件非常有用。 77 | 78 | Bokeh还提供一个强大的命令行工具`bokeh`可以用来生成多种输出。 79 | 80 | ``` 81 | bokeh html 82 | ``` 83 | 84 | 根据任何一种Bokeh应用的资源文件(如Python脚本、Bokeh应用目录、JSON文件)生成独立的HTML文件 85 | 86 | ``` 87 | bokeh json 88 | ``` 89 | 90 | 根据任何一种Bokeh应用的资源文件生成相当于Bokeh文件的序列化JSON文件。 91 | 92 | ``` 93 | bokeh serve 94 | ``` 95 | 96 | 将Bokeh文件作为Web应用发布 97 | 98 | 用`bokeh`命令的好处是不需要在Python代码中指定输出方式,而通过命令来获得多种格式的输出。也就是一次编写,多次输出。上述的代码也可以简化为 99 | 100 | ```python 101 | from bokeh.plotting import figure 102 | 103 | p = figure() 104 | p.line(x=[1, 2, 3], y=[4,6,2]) 105 | ``` 106 | 107 | 现在,你就可以用`bokeh html foo.py`来生成独立的HTML文件,或者用`booked serve foo.py`将Bokeh图形以Web应用的形式发布。更多信息请查看[Using bokeh Commands](http://bokeh.pydata.org/en/latest/docs/user_guide/cli.html#userguide-cli)。 108 | 109 | ### 接口-Interfaces 110 | 111 | Bokeh不仅为数据科学家及相关领域的专家提供了快速便捷的接口,还为软件开发者和工程师们提供了更加丰富的接口来配置更多Bokeh成熟的特性。正因为这个特点,Bokeh的方法是分等级的,不同等级的需求、特性对应不同等级的接口方法,而这些方法的使用方法基本都是相同的,这样就可以提高代码的复用率。这一节中主要向用户概述一些用户级的可用接口和一些中心概念。如果你想直接绘制图形,可以跳过这一章,转向[Plotting with Basic Glyphs](http://bokeh.pydata.org/en/latest/docs/user_guide/plotting.html#userguide-plotting)和[Making High-level Charts](http://bokeh.pydata.org/en/latest/docs/user_guide/charts.html#userguide-charts)。 112 | 113 | #### bokeh.models 114 | 115 | Bokeh实际上是由两个组件库构成的。 116 | 117 | 第一部分是在浏览器中运行的JavaScript库,BokehJS。这个库负责所有的页面渲染和用户交互。BokehJS的输入是一个用来构成整个网页“轮廓”的JSON对象集。这些对象包括图形、挂件中你能看见的所有东西。这些JSON对象在浏览器中最终会被转换成[Backbone](http://backbonejs.org/)模型,并渲染成对应的[Backbone](http://backbonejs.org/)可视化模型。 118 | 119 | 第二个部分是Python库(或者其他语言类型的库,这里以Python作为例子),这些库可以生成上述说的JSON对象。这些都是在库的底层完成的,这些Python类可以将代码中设置的内容和属性序列化成JSON对象。所有这些低级模型都可以在**低级**接口[bokeh.models](http://bokeh.pydata.org/en/latest/docs/reference/models.html#bokeh-models)中找到。大多数类都很简单,只有一些属性,设置没有方法。这些属性可以在创建模型的时候传入,或者在之后指定使用该属性的模型。下面以`Rect`标志对象为例给出例子: 120 | 121 | ```python 122 | # properties can be configured when a model object is initialized 123 | glyph = Rect(x="x", y="y2", w=10, h=20, line_color=None) 124 | 125 | # or by assigning values to attributes on the model later 126 | glyph.fill_alpha = 0.5 127 | glyph.fill_color = "navy" 128 | ``` 129 | 130 | 类似这样的配置活儿可以普遍的适用于所有Bokeh模型。加上Bokeh接口最终生成的都是模型集,所以所有图形、挂件的风格化和配置都可以通过这一方法来实现,并且不限制于使用的是哪个接口。 131 | 132 | 使用[bokeh.models](http://bokeh.pydata.org/en/latest/docs/reference/models.html#bokeh-models)接口可以随意搭配图形和挂件,而这样做的坏处就是结果有时候可能并没有意义或者一塌糊涂,但至少,这可以让开发者亲自参与到构建“轮廓”的过程中来。因为这个原因,大多数用户可能更乐意去使用高级接口(下面会介绍到),除非他们有特殊的需求,而高级接口不提供这一需求。关于更多Bokeh模型的知识请移步 [Reference Guide](http://bokeh.pydata.org/en/latest/docs/reference.html#refguide)。 133 | 134 | #### bokeh.plotting 135 | 136 | plotting接口是Bokeh的**中级**接口,这一接口的使用和[Matplotlib](http://matplotlib.org/)还有[Matlab](http://www.mathworks.com/products/matlab/)中的绘制函数很像。他主要用于让用户选择合适于所用数据的标志,若不指定标志,则图形使用默认的坐标轴、网格线和工具来绘图。所有构建“轮廓”的艰难工序在这一接口中将自动完成。 137 | 138 | [bokeh.plotting](http://bokeh.pydata.org/en/latest/docs/reference/plotting.html#bokeh-plotting)接口的中心类是`Figure`类。`Figure`继承自`Plot`,所以也能非常轻松的在图形中添加各类标志。除此之外,`Figure`也能不费吹灰之力就生成默认坐标轴、网格线还有工具。一般来说,用户会通过调用`figure()`函数来创建一个`Figure`对象。 139 | 140 | [bokeh.plotting](http://bokeh.pydata.org/en/latest/docs/reference/plotting.html#bokeh-plotting)一个典型的用法如下,在代码的下方附带了对应的图形结果 141 | 142 | ```python 143 | from bokeh.plotting import figure, output_file, show 144 | 145 | # create a Figure object 146 | p = figure(width=300, height=300, tools="pan,reset,save") 147 | 148 | # add a Circle renderer to this figure 149 | p.circle([1, 2.5, 3, 2], [2, 3, 1, 1.5], radius=0.3, alpha=0.5) 150 | 151 | # specify how to output the plot(s) 152 | output_file("foo.html") 153 | 154 | # display the figure 155 | show(p) 156 | ``` 157 | 158 | 【图图】 159 | 160 | 注意观察代码,代码中用了`figure()`创建了图形,之后用`Figure.circle`在图中添加了圆标志。可以看见我们并不需要为配置坐标轴或者网格线而操心(如果需要,也可以自行配置),而且添加工具栏上的工具也只需要传入相应的名字即可。在代码的最后我们用了一些输出函数来将图形展示出来。 161 | 162 | > 注意 163 | > 164 | > `output_file()`和`show()`等输出函数可以在[bokeh.io](http://bokeh.pydata.org/en/latest/docs/reference/io.html#bokeh-io)模块中找到,为了方便,这些输出函数也可以从[bokeh.plotting](http://bokeh.pydata.org/en/latest/docs/reference/plotting.html#bokeh-plotting)中导入 165 | 166 | 除了上面的,其实还有许多用法这里没有展示出来,比如不展示转而保存该图形、风格化或去掉坐标轴和网格线、增加别的曲线并将它们显示在一个图形中等。这些用法的示例你都可以在[User Guide](http://bokeh.pydata.org/en/latest/docs/user_guide.html#userguide)的[Plotting with Basic Glyphs](http://bokeh.pydata.org/en/latest/docs/user_guide/plotting.html#userguide-plotting)这一章中看到。 167 | 168 | #### bokeh.charts 169 | 170 | [bokeh.charts](http://bokeh.pydata.org/en/latest/docs/reference/charts.html#bokeh-charts)是Bokeh的一个**高级**接口,主要可以快速的绘制一些静态图表。跟[bokeh.plotting](http://bokeh.pydata.org/en/latest/docs/reference/plotting.html#bokeh-plotting)一样,[bokeh.charts](http://bokeh.pydata.org/en/latest/docs/reference/charts.html#bokeh-charts)是通过整合一些较底层的类来简化创建图表的过程。虽然是简化了过程,但是你还是需要提供必要的一些数据,一般情况下,这一接口中的函数是用来创建普通的示意静态图的,[bokeh.charts](http://bokeh.pydata.org/en/latest/docs/reference/charts.html#bokeh-charts)中的函数会自动为不同组的数据标记不同的颜色和其他一些标识。 171 | 172 | [bokeh.charts](http://bokeh.pydata.org/en/latest/docs/reference/charts.html#bokeh-charts)中快速绘图的类型包括`Bar()`、`BoxPlot()`、`Histogram()`、`TimeSeries()`(分别对应柱状图、箱图、直方图、时间序列图)等,下面以`Scatter()`作散点图为例给出代码 173 | 174 | ```python 175 | from bokeh.charts import Scatter, output_file, show 176 | 177 | # prepare some data, a Pandas GroupBy object in this case 178 | from bokeh.sampledata.autompg import autompg as df 179 | 180 | # create a scatter chart 181 | p = Scatter(df, x='mpg', y='hp', color='cyl', 182 | title="MPG vs HP (colored by CYL)", 183 | legend='top_right', 184 | xlabel="Miles Per Gallon", 185 | ylabel="Horsepower") 186 | 187 | # specify how to output the plot(s) 188 | output_file("chart.html") 189 | 190 | # display the figure 191 | show(p) 192 | ``` 193 | 194 | 【图图】 195 | 196 | 需要指出的是输出函数像`output_file()`和`show()`之类的被普遍的用在各个绘图接口中,就像[bokeh.plotting](http://bokeh.pydata.org/en/latest/docs/reference/plotting.html#bokeh-plotting)中也有`output_file()`和`show()`一样。他虽然是定义在[bokeh.io](http://bokeh.pydata.org/en/latest/docs/reference/io.html#bokeh-io)模块中的,但是为了方便也可以从[bokeh.charts](http://bokeh.pydata.org/en/latest/docs/reference/charts.html#bokeh-charts)中导入。 197 | 198 | #### 其他接口-Other Interfaces 199 | 200 | Bokeh与[Matplotlib](http://matplotlib.org/)具有一定的共存性,你可以用第三方库[mplexporter](https://github.com/mpld3/mplexporter)绘制图形,之后再转化成Bokeh图形,虽然不能100%利用[Matplotlib](http://matplotlib.org/)的特性,但是有时候Bokeh这一特点非常实用。除了刚刚说的[Matplotlib](http://matplotlib.org/)图形,你也可以非常轻易的将用[Seaborn](http://stanford.edu/~mwaskom/software/seaborn/)和[ggplot.py](https://github.com/yhat/ggplot)绘制出来的图形转化成Bokeh图形。下面这个例子只用了一行代码将[Seaborn](http://stanford.edu/~mwaskom/software/seaborn/)图形转化成了Bokeh图形。 201 | 202 | ```python 203 | import seaborn as sns 204 | 205 | from bokeh import mpl 206 | from bokeh.plotting import output_file, show 207 | 208 | tips = sns.load_dataset("tips") 209 | 210 | sns.set_style("whitegrid") 211 | 212 | ax = sns.violinplot(x="day", y="total_bill", hue="sex", 213 | data=tips, palette="Set2", split=True, 214 | scale="count", inner="stick") 215 | 216 | output_file("violin.html") 217 | 218 | show(mpl.to_bokeh()) 219 | ``` 220 | 221 | 【图图】 222 | 223 | -------------------------------------------------------------------------------- /tmp/快速入门(DonaldDai).md: -------------------------------------------------------------------------------- 1 | ## 快速入门-Quickstart 2 | 3 | 原文 [Quickstart](http://bokeh.pydata.org/en/latest/docs/user_guide/quickstart.html) 4 | 5 | ### 介绍-Introduction 6 | 7 | Bokeh是致力于网页浏览器展示的Python交互式图表库。Bokeh能读取巨大的数据集或者流数据以简单快捷的方式为网页提供优美、简洁、高交互性能的图形。 8 | 9 | 为了能让用户高度自定义简单、高性能、灵活的图表,Bokeh开放三个层次的接口给用户: 10 | 11 | -  [`bokeh.models`](http://bokeh.pydata.org/en/latest/docs/reference/models.html#bokeh-models)  低级接口,能为app开发者提供高度灵活的图形表示(可以自定义一些顶层的组件) 12 | -  [`bokeh.plotting`](http://bokeh.pydata.org/en/latest/docs/reference/plotting.html#bokeh-plotting)  中级接口,该接口主要用于绘制曲线(默认加载一些低级的组件) 13 | -  [`bokeh.charts`](http://bokeh.pydata.org/en/latest/docs/reference/charts.html#bokeh-charts) 高级接口,能快速简单地构建复杂的图形 14 | 15 | 快速入门只能主要运用 [bokeh.plotting](http://bokeh.pydata.org/en/latest/docs/reference/plotting.html#bokeh-plotting)接口 16 | 17 | ### 快速安装-Quick Installation 18 | 19 | Bokeh有多种安装方式,Bokeh推荐在 [Anaconda Python distribution](http://continuum.io/anaconda)的命令窗口来安装,这是最简单的方法。 20 | 21 | ``` 22 | conda install bokeh 23 | ``` 24 | 25 | 该命令会安装Bokeh所有的依赖包。 26 | 27 | Anaconda最小安装适用于包括Windows等大多数系统,在安装的同时也会在Anaconda的根目录中创建一个`examples/`的子目录,其中包含了一些例子。 28 | 29 | 如果你已经安装了Bokeh所有的依赖包,比如Numpy,那么你也可以通过`pip`来安装: 30 | 31 | ``` 32 | pip install bokeh 33 | ``` 34 | 35 | >注意 36 | > 37 | >pip安装方式不安装示例。若要查看示例可以`Clone`下Git仓库中的`examples/`到本地。[HELP此处应有超链接] 38 | 39 | ### 开始-Getting Started 40 | 41 | Bokeh是一个很大的库,功能丰富,而这一章节中只是对Bokeh常用的示例和工作流进行简单讲解。若要了解更多功能,请参见 [User Guide](http://bokeh.pydata.org/en/latest/docs/user_guide.html#userguide) 42 | 43 | 下面是一些示例 44 | 45 | 以Python列表(List)作为参数传入绘制带交互工具(缩放、画笔、自适应大小、保存等)的图 46 | 47 | ```python 48 | from bokeh.plotting import figure, output_file, show 49 | 50 | # prepare some data 51 | x = [1, 2, 3, 4, 5] 52 | y = [6, 7, 2, 4, 5] 53 | 54 | # output to static HTML file 55 | output_file("lines.html") 56 | 57 | # create a new plot with a title and axis labels 58 | p = figure(title="simple line example", x_axis_label='x', y_axis_label='y') 59 | 60 | # add a line renderer with legend and line thickness 61 | p.line(x, y, legend="Temp.", line_width=2) 62 | 63 | # show the results 64 | show(p) 65 | ``` 66 | 67 | ![](/img/QS_GS1.png) 68 | 69 | [交互图](/jupyter/QS_GS1.ipynb) 70 | 71 | 当运行这段代码之后,会在项目当前目录下创建一个`"lines.html"`文件,并且浏览器会自动打开一个新标签页来显示刚刚创建的图表(为展示需要,会把代码生成的图形放在此文档中,以供参考) 72 | 73 | 用 [`bokeh.plotting`](http://bokeh.pydata.org/en/latest/docs/reference/plotting.html#bokeh-plotting)接口创建图表的基本步骤如下: 74 | 75 | - 准备一些数据(在上面的例子中,数据是一个简单的Python列表) 76 | - 指定一个输出(在上面的例子中,用`output_file()`函数指定了输出文件名为`"lines.html"`) 77 | - 调用`figure()`函数创建图表容器并指定一些整体参数,比如title、tools和axes labels 78 | - 将数据传入渲染函数(在上面的例子中是`Figure.line`函数)并指定一些视觉参数,比如colors、legends和widths 79 | - 调用`show()`或者`save()`来显示或保存结果 80 | 81 | 步骤三、四可以重复使用来绘制多个图形,多图形绘制可以参考在下面的例子 82 | 83 | 若要用 [bokeh.plotting](http://bokeh.pydata.org/en/latest/docs/reference/plotting.html#bokeh-plotting) 自定义添加更多数据、曲线或对数轴非常方便简洁的,比如在一个图形中同时绘制多条曲线的代码如下: 84 | 85 | ```python 86 | from bokeh.plotting import figure, output_file, show 87 | 88 | # prepare some data 89 | x = [0.1, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0] 90 | y0 = [i**2 for i in x] 91 | y1 = [10**i for i in x] 92 | y2 = [10**(i**2) for i in x] 93 | 94 | # output to static HTML file 95 | output_file("log_lines.html") 96 | 97 | # create a new plot 98 | p = figure( 99 | tools="pan,box_zoom,reset,save", 100 | y_axis_type="log", y_range=[0.001, 10**11], title="log axis example", 101 | x_axis_label='sections', y_axis_label='particles' 102 | ) 103 | 104 | # add some renderers 105 | p.line(x, x, legend="y=x") 106 | p.circle(x, x, legend="y=x", fill_color="white", size=8) 107 | p.line(x, y0, legend="y=x^2", line_width=3) 108 | p.line(x, y1, legend="y=10^x", line_color="red") 109 | p.circle(x, y1, legend="y=10^x", fill_color="red", line_color="red", size=6) 110 | p.line(x, y2, legend="y=10^x^2", line_color="orange", line_dash="4 4") 111 | 112 | # show the results 113 | show(p) 114 | ``` 115 | 116 | ![](/img/QS_GS2.png) 117 | 118 | [交互图](/jupyter/QS_GS2.ipynb) 119 | 120 | ### Jupyter Notebooks上的应用-Jupyter Notebooks 121 | 122 | 在这一小节中,我们将会讲解Jypyter Notebooks上Bokeh的使用 123 | 124 | Jupyter Notebooks是一款风靡于“PyData”社区的强大的数据分析工具。Bokeh无缝整合了Jupyter Notebooks和Bokeh。如果想在Notebook中查看之前的示例,只需要将`output_file()`替换成`output_notebook()`即可,注意这里`output_notebook()`不需要参数。 125 | 126 | 在 [Bokeh NBViewer Gallery](http://nbviewer.ipython.org/github/bokeh/bokeh-notebooks/blob/master/index.ipynb)还有许多静态示例,有兴趣的可以去看看。 127 | 128 | 在 [Bokeh GitHub repository](https://github.com/bokeh/bokeh)上也有大量的notebook示例,若想要查看,可以`clone`下整个仓库,之后再命令行中进入其中的`examples/howto`子目录,接着运行 129 | 130 | ``` 131 | ipython notebook 132 | ``` 133 | 134 | 你可以在自动弹出的索引页直接打开其中的文件或者执行任何其他交互操作。特别是你可以从以下两个例子中体会到Bokeh是如何与Jupyter挂件协同工作的。 135 | 136 | [examples/howto/notebook_comms/Jupyter Interactors.ipynb](https://github.com/bokeh/bokeh/tree/0.12.1/examples/howto/notebook_comms/Jupyter%20Interactors.ipynb) 137 | 138 | [examples/howto/notebook_comms/Numba Image Example.ipynb](https://github.com/bokeh/bokeh/tree/0.12.1/examples/howto/notebook_comms/Numba%20Image%20Example.ipynb) 139 | 140 | ### 多语言支持-Other Languages 141 | 142 | Bokeh的体系结构使得Bokeh能够非常容易的为其他语言提供使用接口,其中有一些小众语言的接口已经存在(比如R,Scala,Julia)。尽管我们团队是Python的忠实粉丝,但是我们也同时在开发着不同语言的Bokeh库,可以通过以下链接查看已经编译完的一些多语言Bokeh库 143 | 144 | - [Bokeh for R](http://hafen.github.io/rbokeh/) 145 | - [Bokeh for Scala](https://github.com/bokeh/bokeh-scala) 146 | - [Bokeh for Julia](https://github.com/bokeh/Bokeh.jl) 147 | 148 | ### 示例数据-Sample Data 149 | 150 | 示例中所用的数据和示例是分开存放的,若要下载这些数据,可以在Bash或者Windows命令提示符后键入命令 151 | 152 | ``` 153 | bokeh sampledata 154 | ``` 155 | 156 | ### 相关概念-Concepts 157 | 158 | 根据上面的一些例子,这里提出一些核心概念 159 | 160 | #### 图形-Plot 161 | 162 | 图形是Bokeh的中心概念。图形在Bokeh中指的是容纳曲线、指示、数据、工具等几乎所有用来展示的元素的一个容器。具体的,Bokeh中的 [`bokeh.plotting`](http://bokeh.pydata.org/en/latest/docs/reference/plotting.html#bokeh-plotting)接口提供了一个 `Figure`类来聚集所有这些必要的元素,而`Fighure`实例可以很方便的由`figure()`函数来创建 163 | 164 | #### 标示-Glyphs 165 | 166 | 标示是Bokeh中的基础视觉元素。在Bokeh的底层,标示以**glyph对象**存在,比如`Line`。如果你要使用低级接口[`bokeh.models`](http://bokeh.pydata.org/en/latest/docs/reference/models.html#bokeh-models)来绘制图形,那么你还需要创建所有必要的Bokeh对象,其中包括上面提到的glyph对象和对应的数据集。为了使用更方便,[`bokeh.plotting`](http://bokeh.pydata.org/en/latest/docs/reference/plotting.html#bokeh-plotting)提供一个更高级的**glyph方法**像本章第一个示例中用的`Figure.line`就是其中一个。第二个示例中增加了`Figure.circle`来同时显示曲线和圆。除了曲线和圆,Bokeh还有许多可选的[标示](http://bokeh.pydata.org/en/latest/docs/reference/models/glyphs.html#bokeh-models-glyphs)和[标志](http://bokeh.pydata.org/en/latest/docs/reference/models/markers.html#bokeh-models-markers)。 167 | 168 | 视觉元素的外观和数据的值是紧密相关的。在上面的例子中,我们可以看到*x*和*y*参数是可以被赋值为向量的。但其实标示还有许多可选的属性参数,如[线形属性](http://bokeh.pydata.org/en/latest/docs/user_guide/styling.html#userguide-styling-line-properties)、[填充属性](http://bokeh.pydata.org/en/latest/docs/user_guide/styling.html#userguide-styling-fill-properties)和[文字属性](http://bokeh.pydata.org/en/latest/docs/user_guide/styling.html#userguide-styling-text-properties)。所有这些参数都可以以向量的形式赋值给参数,在下面会给出相关示例 169 | 170 | #### 指示&说明-Guides and Annotations 171 | 172 | Bokeh还提供一些别的视觉组件才帮助用户更好的展示或者让用户在图中做比较。这一类组件分为两类 173 | 174 | - 指示(Guides):指示的作用主要是帮助用户判断图中的距离,角度等。具体的包括格线、坐标轴等 175 | - 说明(Annotations):说明主要包括图中的标签部分,具体的比如有标题,图例等 176 | 177 | #### 数据范围-Ranges 178 | 179 | 数据范围指的是绘图过程中所使用的数据的上界与下界。默认情况下,用[`bokeh.plotting`](http://bokeh.pydata.org/en/latest/docs/reference/plotting.html#bokeh-plotting)接口绘制出的图像时,Bokeh的`DataRangeld`对象会根据所用数据计算出数据范围,之后传给绘图函数。当然,数据范围也可以手动传入,只需要在绘图时传入如下参数,参数可以接受Python中的列表或者二元元组形式的赋值 180 | 181 | ```python 182 | p = figure(x_range=[0,10], y_range=(10, 20)) 183 | ``` 184 | 185 | #### 相关资源-Resources 186 | 187 | 若要在用户本地展示图形,要求所使用的浏览器加载Bokeh的JS和CSS文件。默认情况下,`output_file()`函数会自动在生成的HTML中加载来自 [http://cdn.pydata.org](http://cdn.pydata.org/) 的样式文件。但是,你也可以将文件下载下来,之后再本地载入,若要使用这种方式请在`output_file()`函数中添加参数`mode="inline"`。 188 | 189 | ### 更多例子-More examples 190 | 191 | 下面给出更多在别的场合下经常会用到的例子,所有这些例子都是用[`bokeh.plotting`](http://bokeh.pydata.org/en/latest/docs/reference/plotting.html#bokeh-plotting)接口绘制的。 192 | 193 | #### 参数向量化-Vectorized colors and sizes 194 | 195 | 这个例子主要演示如何传入一系列的数据给绘图参数如`fill_color`和`radius`。你也可以在这个例子中找到以下情况的用法: 196 | 197 | - 传入一个包含工具名称的列表给`figure()` 198 | - 用`mode`参数从CDN获取BokehJS文件 199 | - 自定义`x_range`和`y_range`参数 200 | - 传入空值`None`来*擦掉*一条曲线 201 | - 运用Numpy数组来传入数据 202 | 203 | ```python 204 | import numpy as np 205 | 206 | from bokeh.plotting import figure, output_file, show 207 | 208 | # prepare some data 209 | N = 4000 210 | x = np.random.random(size=N) * 100 211 | y = np.random.random(size=N) * 100 212 | radii = np.random.random(size=N) * 1.5 213 | colors = [ 214 | "#%02x%02x%02x" % (int(r), int(g), 150) for r, g in zip(50+2*x, 30+2*y) 215 | ] 216 | 217 | # output to static HTML file (with CDN resources) 218 | output_file("color_scatter.html", title="color_scatter.py example", mode="cdn") 219 | 220 | TOOLS="resize,crosshair,pan,wheel_zoom,box_zoom,reset,box_select,lasso_select" 221 | 222 | # create a new plot with the tools above, and explicit ranges 223 | p = figure(tools=TOOLS, x_range=(0,100), y_range=(0,100)) 224 | 225 | # add a circle renderer with vectorized colors and sizes 226 | p.circle(x,y, radius=radii, fill_color=colors, fill_alpha=0.6, line_color=None) 227 | 228 | # show the results 229 | show(p) 230 | ``` 231 | 232 | ![](/img/QS_ME_VCS.png) 233 | 234 | [交互图](/jupyter/QS_ME_VCS.ipynb) 235 | 236 | #### 数据联动-Linked panning and brushing 237 | 238 | > 什么是数据联动? 239 | > 240 | > 在这个例子中,数据联动指的是一个图形中的数据变化会影响到另一个图形中的数据 241 | 242 | 有时候在不同的图形中添加联动的数据曲线更有利于战术数据。在Bokeh中进行数据联动,一般只需在几个图形间传递将组件参数即可。下面的例子演示了在Bokeh的笔工具联动**(linked panning)**,方法是在图形间传递几个组件参数。你也可以在下面的例子中找到一下情况的用法: 243 | 244 | - 通过多次调用`figure()`函数来创建多个图形 245 | - 用`gridplot()`函数来排列多个图形 246 | - 用`Figure.triangle`和`Figure.square`在图形中添加新的标识 247 | - 通过调节`toolbar_location`的值为`None`来隐藏工具栏 248 | - `line_color`、`fill_color`、`line_alpha`、`fill_alpha`属性的用法 249 | 250 | ```python 251 | import numpy as np 252 | 253 | from bokeh.layouts import gridplot 254 | from bokeh.plotting import figure, output_file, show 255 | 256 | # prepare some data 257 | N = 100 258 | x = np.linspace(0, 4*np.pi, N) 259 | y0 = np.sin(x) 260 | y1 = np.cos(x) 261 | y2 = np.sin(x) + np.cos(x) 262 | 263 | # output to static HTML file 264 | output_file("linked_panning.html") 265 | 266 | # create a new plot 267 | s1 = figure(width=250, plot_height=250, title=None) 268 | s1.circle(x, y0, size=10, color="navy", alpha=0.5) 269 | 270 | # NEW: create a new plot and share both ranges 271 | s2 = figure(width=250, height=250, x_range=s1.x_range, y_range=s1.y_range, title=None) 272 | s2.triangle(x, y1, size=10, color="firebrick", alpha=0.5) 273 | 274 | # NEW: create a new plot and share only one range 275 | s3 = figure(width=250, height=250, x_range=s1.x_range, title=None) 276 | s3.square(x, y2, size=10, color="olive", alpha=0.5) 277 | 278 | # NEW: put the subplots in a gridplot 279 | p = gridplot([[s1, s2, s3]], toolbar_location=None) 280 | 281 | # show the results 282 | show(p) 283 | ``` 284 | 285 | ![](/img/QS_ME_LPB1.png) 286 | 287 | [交互图](/jupyter/QS_ME_LPB1.ipynb) 288 | 289 | 尽管工具栏是隐藏的,但是笔工具仍然处于激活状态。点击并拖动图形可以改变坐标轴的范围,同时你也可以观察到三个图形的坐标轴数据是怎么联动的 290 | 291 | 另一个例子是**选择联动(linked brushing)**, 实现的方式是在两个图形中传递[`ColumnDataSource`](http://bokeh.pydata.org/en/latest/docs/reference/models/sources.html#bokeh.models.sources.ColumnDataSource)数据结构参数。 292 | 293 | ```python 294 | import numpy as np 295 | from bokeh.plotting import * 296 | from bokeh.models import ColumnDataSource 297 | 298 | # prepare some date 299 | N = 300 300 | x = np.linspace(0, 4*np.pi, N) 301 | y0 = np.sin(x) 302 | y1 = np.cos(x) 303 | 304 | # output to static HTML file 305 | output_file("linked_brushing.html") 306 | 307 | # NEW: create a column data source for the plots to share 308 | source = ColumnDataSource(data=dict(x=x, y0=y0, y1=y1)) 309 | 310 | TOOLS = "pan,wheel_zoom,box_zoom,reset,save,box_select,lasso_select" 311 | 312 | # create a new plot and add a renderer 313 | left = figure(tools=TOOLS, width=350, height=350, title=None) 314 | left.circle('x', 'y0', source=source) 315 | 316 | # create another new plot and add a renderer 317 | right = figure(tools=TOOLS, width=350, height=350, title=None) 318 | right.circle('x', 'y1', source=source) 319 | 320 | # put the subplots in a gridplot 321 | p = gridplot([[left, right]]) 322 | 323 | # show the results 324 | show(p) 325 | ``` 326 | 327 | ![](/img/QS_ME_LPB2.png) 328 | 329 | [交互图](/jupyter/QS_ME_LPB2.ipynb) 330 | 331 | 选择方形选择工具(box select)或者套索选择工具(lasso select)在其中一个图形中进行操作,这个操作会联动另一个图形。 332 | 333 | #### 时间序列图形-Datetime axes 334 | 335 | 处理时间序列数据是数据分析中另一常见的情形。Bokeh有一个成熟的类 [`DatetimeAxis`](http://bokeh.pydata.org/en/latest/docs/reference/models/axes.html#bokeh.models.axes.DatetimeAxis),可以根据现有的图形来生成时间序列图形。[`DatetimeAxis`](http://bokeh.pydata.org/en/latest/docs/reference/models/axes.html#bokeh.models.axes.DatetimeAxis)的一些坐标轴的参数有默认值,当然你也可以不用[`DatetimeAxis`](http://bokeh.pydata.org/en/latest/docs/reference/models/axes.html#bokeh.models.axes.DatetimeAxis)而看情况直接将`figure()`中`x_axis_type`或`y_axis_type`的值设为`"datetime"`来说明绘图的类型是时间序列。 336 | 337 | 这个例子中也有一些有趣的用法: 338 | 339 | - 设置`figure()`函数中的`width`和`height`参数 340 | - 通过改变参数自定义图形和其他对象 341 | - 通过设置`figure`的参数(如`legend`、`grid`、`xgrid`、`ygrid`、`axis`、`xaxis`、`yaxis`)来调整图形中的注释 342 | 343 | ```python 344 | import numpy as np 345 | 346 | from bokeh.plotting import figure, output_file, show 347 | from bokeh.sampledata.stocks import AAPL 348 | 349 | # prepare some data 350 | aapl = np.array(AAPL['adj_close']) 351 | aapl_dates = np.array(AAPL['date'], dtype=np.datetime64) 352 | 353 | window_size = 30 354 | window = np.ones(window_size)/float(window_size) 355 | aapl_avg = np.convolve(aapl, window, 'same') 356 | 357 | # output to static HTML file 358 | output_file("stocks.html", title="stocks.py example") 359 | 360 | # create a new plot with a a datetime axis type 361 | p = figure(width=800, height=350, x_axis_type="datetime") 362 | 363 | # add renderers 364 | p.circle(aapl_dates, aapl, size=4, color='darkgrey', alpha=0.2, legend='close') 365 | p.line(aapl_dates, aapl_avg, color='navy', legend='avg') 366 | 367 | # NEW: customize by setting attributes 368 | p.title.text = "AAPL One-Month Average" 369 | p.legend.location = "top_left" 370 | p.grid.grid_line_alpha=0 371 | p.xaxis.axis_label = 'Date' 372 | p.yaxis.axis_label = 'Price' 373 | p.ygrid.band_fill_color="olive" 374 | p.ygrid.band_fill_alpha = 0.1 375 | 376 | # show the results 377 | show(p) 378 | ``` 379 | 380 | ![](/img/QS_ME_DA.png) 381 | 382 | [交互图](/jupyter/QS_ME_DA.ipynb) 383 | 384 | > 注意 385 | > 386 | > 这里绘图需要下载一些官方资源,已经下载的上述代码运行不会出问题,如果上述代码运行出错请根据提示 387 | > 388 | > ```python 389 | > from bokeh.sampledata import download 390 | > download() 391 | > ``` 392 | > 393 | > 下载相关资源 394 | 395 | ### Bokeh图形服务器-Bokeh Plot Server 396 | 397 | Bokeh服务器是一个可选的组件项。尽管没有Bokeh图形服务器,我们一样可以创建出有趣、可交互的可视化数据。但是Bokeh还有一些新颖、强大的能力或许你会想用到 398 | 399 | - 用UI和选项来驱动图形的计算和更新 400 | - 能够降低大型数据集采样率的智能服务端 401 | - 通过流数据自动更新图形 402 | - 适用于大数据的成熟图形重绘系统 403 | - 发布更易于普通用户操作的可视化图形 404 | 405 | 由于空间有限,不能在快速入门中讲解所有的用法,读者可以现在下面这个例子中感受一些Bokeh图形服务器的强大。 406 | 407 | ![](/img/QS_BPS.png) 408 | 409 | 你可以在 [Gallery](http://bokeh.pydata.org/en/latest/docs/gallery.html#gallery)的 [Server App Examples](http://bokeh.pydata.org/en/latest/docs/gallery.html#gallery-server-examples)部分中找到更多有关图形服务器绘图的例子。想要知道更多图形服务器的细节请移步 [User Guide](http://bokeh.pydata.org/en/latest/docs/user_guide.html#userguide)的[Running a Bokeh Server](http://bokeh.pydata.org/en/latest/docs/user_guide/server.html#userguide-server)部分 410 | 411 | ### 下一步干啥?-What’s next? 412 | 413 | 【困了。睡觉。。。】 414 | 415 | -------------------------------------------------------------------------------- /tmp/插入图表或Apps(DonaldDai).md: -------------------------------------------------------------------------------- 1 | ## 嵌入图表和Apps-Embedding Plots and Apps 2 | 3 | 原文 [Embedding Plots and Apps](http://bokeh.pydata.org/en/latest/docs/user_guide/embed.html) 4 | 5 | Bokeh提供了多种方式来为HMTL插入图表 6 | 7 | ### 生成单独的HTML文件 8 | 9 | Bokeh的`file_html()`函数能生成包含图表的独立HTML文件,该文件的模板能用Bokeh自带的,也可以用自己的(具体自己查阅`file_html()`函数的文档,例子 [gapminder example plot](https://github.com/bokeh/bokeh/blob/master/examples/howto/interactive_bubble/gapminder.py))。HTML文件包含了图表的所有信息并且是可移植的,同时每张图表旁边的交互工具不会消失。 10 | 11 | 例子: 12 | 13 | ```python 14 | from bokeh.plotting import figure 15 | from bokeh.resources import CDN 16 | from bokeh.embed import file_html 17 | 18 | plot = figure() 19 | plot.circle([1,2], [3,4]) 20 | 21 | html = file_html(plot, CDN, "my plot") 22 | ``` 23 | 24 | 其中,`html`中的文本可以用Python自带函数保存到一个文件中 25 | 26 | > 注意 27 | > 28 | > 这个方法相对比较低级、直接,在后面的内容中会教大家用`bokeh.plotting`和`bokeh.charts`中的接口配合[`output_file()`](http://bokeh.pydata.org/en/latest/docs/reference/io.html#bokeh.io.output_file)、[`show()`](http://bokeh.pydata.org/en/latest/docs/reference/io.html#bokeh.io.show)、[`save()`](http://bokeh.pydata.org/en/latest/docs/reference/io.html#bokeh.io.save)函数来达到相同的效果 29 | 30 | ### 作为组件嵌入到HTML中 31 | 32 | Bokeh提供`components()`函数来生成组件形式的图标代码。`components()`返回 33 | 34 | - 一个` 72 | ``` 73 | 74 | `div`长这样 75 | 76 | ```html 77 |
78 | ``` 79 | 80 | 得到了`script`和`div`之后还不能够显示图表,还需将Bokeh官方的`.css`和`.js`文件引用过来才行,也可以将官方的文件下载到本地来加载。引用只需要在``标签中加入如下代码 81 | 82 | ```html 83 | 86 | 89 | 90 | 91 | 92 | ``` 93 | 94 | 其中文件名中有"-widget"的引用文件只有在你需要用到**Bokeh widgets**时才会用到,平时可以不引用来节省页面加载的时间。的`x.y.z`指的是版本号,比如现在要引用**0.12.0**版本的Bokeh,则代码应该长这样 95 | 96 | ```html 97 | 100 | 103 | 104 | 105 | 106 | ``` 107 | 108 | > 注意 109 | > 110 | > 不然可能会加载失败 111 | 112 | 例子: 113 | 114 | 一个完整的HTML文件长这样 115 | 116 | ```html 117 | 118 | 119 | 120 | 121 | Bokeh Scatter Plots 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | ``` 134 | 135 | `component()`函数能接受单个Bokeh图表模型作为参数,也能接受包含Bokeh图表模型的列表(List)、元组(tuple)、字典(dictionary)作为参数,其返回值是包含`script`和`div`文本的对应数据结构。 136 | 137 | ### 在IPython Notebook中嵌入图表 138 | 139 | `notebook_div()`函数能够生成适用于IPython Notebook嵌入的文本包,只有一个输出。文本包中包含`script`和`div`文本。 140 | 141 | ```python 142 | from bokeh.plotting import figure 143 | from bokeh.embed import notebook_div 144 | 145 | plot = figure() 146 | plot.circle([1,2], [3,4]) 147 | 148 | div = notebook_div(plot) 149 | ``` 150 | 151 | 返回的内容和`components()`大体相同,这里不再显示出来 152 | 153 | > 注意 154 | > 155 | > 这个方法相对比较低级、直接,在后面的内容中会教大家用`bokeh.plotting`和`bokeh.charts`中的接口配合 [`output_notebook()`](http://bokeh.pydata.org/en/latest/docs/reference/io.html#bokeh.io.output_notebook)、[`save()`](http://bokeh.pydata.org/en/latest/docs/reference/io.html#bokeh.io.save)函数来达到相同的效果 156 | 157 | ### 自动加载的嵌入方式 158 | 159 | Bokeh提供了一种自动加载的方式来嵌入图表,自动加载的形式是将一段` 191 | ``` 192 | 193 | > 注意 194 | > 195 | > 要让script文本执行得要Bokeh server处于运行状态 196 | 197 | 如果你已经有app在Bokeh服务器上并且还有app的url,那么替换代码如下 198 | 199 | ```python 200 | script = autoload_server(model=None, app_path="/apps/slider", url="https://demo.bokehplots.com") 201 | ``` 202 | 203 | 更多细节参见 [autoload_server()](http://bokeh.pydata.org/en/latest/docs/reference/embed.html#bokeh.embed.autoload_server) 204 | 205 | #### 从静态文件中获取数据 206 | 207 | 如果不想使用Bokeh服务器的话,也可以用`autoload_static()`函数生成引用静态数据的` 234 | ``` 235 | 236 | `script`文本要保存在能够索引到“`some/path`"的路径上的HTML中 237 | 238 | > 注意 239 | > 240 | > 由于