"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"f, ax= plt.subplots(figsize=(8,4)); \n",
"plt.plot(xdf.index, xdf['A'], lw=2, color='b');\n",
"ax.set_xlim(40,80)\n",
"ax.grid(color='0.8')\n",
"plugins.connect(f, plugins.MousePosition(fontsize=16))"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"mpld3.save_html(f, './mpld3_figure.html')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"+ [open in a new tab](./mpld3_figure.html)\n",
"\n",
"+ [some more examples](http://mpld3.github.io/examples/index.html) from the mpld3 gallery\n",
"\n",
"
"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## BOKEH"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[bokeh](http://bokeh.pydata.org/) is a library developed by [continuum analytics](http://continuum.io) \n",
"\n",
"from their website:\n",
"\n",
"*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, but also deliver 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.*"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To know more about bokeh: \n",
" \n",
"[http://bokeh.pydata.org/](http://bokeh.pydata.org/)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"if you use the [anaconda python distribution](), all the bokeh examples are saved in \n",
"\n",
" ${anaconda}/Examples/bokeh "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"prepare the data: simple sine"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"x = np.linspace(0, 10, 1000)\n",
"y = np.sin(x)"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from bokeh.plotting import figure, output_file, output_notebook, show"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"\n",
" \n",
"
\n",
"
Loading BokehJS ...\n",
"
"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
"(function(global) {\n",
" function now() {\n",
" return new Date();\n",
" }\n",
"\n",
" if (typeof (window._bokeh_onload_callbacks) === \"undefined\") {\n",
" window._bokeh_onload_callbacks = [];\n",
" }\n",
"\n",
" function run_callbacks() {\n",
" window._bokeh_onload_callbacks.forEach(function(callback) { callback() });\n",
" delete window._bokeh_onload_callbacks\n",
" console.info(\"Bokeh: all callbacks have finished\");\n",
" }\n",
"\n",
" function load_libs(js_urls, callback) {\n",
" window._bokeh_onload_callbacks.push(callback);\n",
" if (window._bokeh_is_loading > 0) {\n",
" console.log(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n",
" return null;\n",
" }\n",
" if (js_urls == null || js_urls.length === 0) {\n",
" run_callbacks();\n",
" return null;\n",
" }\n",
" console.log(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n",
" window._bokeh_is_loading = js_urls.length;\n",
" for (var i = 0; i < js_urls.length; i++) {\n",
" var url = js_urls[i];\n",
" var s = document.createElement('script');\n",
" s.src = url;\n",
" s.async = false;\n",
" s.onreadystatechange = s.onload = function() {\n",
" window._bokeh_is_loading--;\n",
" if (window._bokeh_is_loading === 0) {\n",
" console.log(\"Bokeh: all BokehJS libraries loaded\");\n",
" run_callbacks()\n",
" }\n",
" };\n",
" s.onerror = function() {\n",
" console.warn(\"failed to load library \" + url);\n",
" };\n",
" console.log(\"Bokeh: injecting script tag for BokehJS library: \", url);\n",
" document.getElementsByTagName(\"head\")[0].appendChild(s);\n",
" }\n",
" };\n",
"\n",
" var js_urls = ['https://cdn.pydata.org/bokeh/release/bokeh-0.11.1.min.js', 'https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.11.1.min.js', 'https://cdn.pydata.org/bokeh/release/bokeh-compiler-0.11.1.min.js'];\n",
"\n",
" var inline_js = [\n",
" function(Bokeh) {\n",
" Bokeh.set_log_level(\"info\");\n",
" },\n",
" \n",
" function(Bokeh) {\n",
" Bokeh.$(\"#63153236-ed3a-4a2e-930a-d1925c30f5d8\").text(\"BokehJS successfully loaded\");\n",
" },\n",
" function(Bokeh) {\n",
" console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-0.11.1.min.css\");\n",
" Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-0.11.1.min.css\");\n",
" console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.11.1.min.css\");\n",
" Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.11.1.min.css\");\n",
" }\n",
" ];\n",
"\n",
" function run_inline_js() {\n",
" for (var i = 0; i < inline_js.length; i++) {\n",
" inline_js[i](window.Bokeh);\n",
" }\n",
" }\n",
"\n",
" if (window._bokeh_is_loading === 0) {\n",
" console.log(\"Bokeh: BokehJS loaded, going straight to plotting\");\n",
" run_inline_js();\n",
" } else {\n",
" load_libs(js_urls, function() {\n",
" console.log(\"Bokeh: BokehJS plotting callback run at\", now());\n",
" run_inline_js();\n",
" });\n",
" }\n",
"}(this));"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"output_notebook()"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
" \n",
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<Bokeh Notebook handle for In[20]>
"
],
"text/plain": [
""
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# create a new plot with a title and axis labels\n",
"p = figure(title=\"simple line example\", x_axis_label='x', y_axis_label='y')\n",
"\n",
"# add a line renderer with legend and line thickness\n",
"p.line(x, y, legend=\"sin(x)\", line_width=2)\n",
"\n",
"# show the results\n",
"show(p)"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"!open sin.html"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Or you can output to an HTML file\n",
"\n",
"**specify mode = \"cdn\" so it loads the javascript from the bokeh Content Delivery Network instead of \n",
"the local copy**"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
" \n",
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<Bokeh Notebook handle for In[22]>
"
],
"text/plain": [
""
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"output_file(\"sin.html\", title=\"sin(x)\", mode=\"cdn\")\n",
"\n",
"# create a new plot with a title and axis labels\n",
"p = figure(title=\"simple line example\", x_axis_label='x', y_axis_label='y')\n",
"\n",
"# add a line renderer with legend and line thickness\n",
"p.line(x, y, legend=\"sin(x)\", line_width=2)\n",
"\n",
"# show the results\n",
"show(p)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can control the toolbar: here I want pan, box_zoom, rest, but not save etc "
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
" \n",
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<Bokeh Notebook handle for In[23]>
"
],
"text/plain": [
""
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"x = np.array([0.1, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0])\n",
"y0 = x**2\n",
"y1 = 10**x\n",
"y2 = 10**(x**2)\n",
"\n",
"# output to static HTML file\n",
"output_file(\"log_lines.html\")\n",
"\n",
"# create a new plot\n",
"p = figure(\n",
" tools=\"pan,box_zoom,reset\",\n",
" y_axis_type=\"log\", y_range=[0.001, 10**11], title=\"log axis example\",\n",
" x_axis_label='sections', y_axis_label='particles'\n",
")\n",
"\n",
"# add some renderers\n",
"p.line(x, x, legend=\"y=x\")\n",
"p.circle(x, x, legend=\"y=x\", fill_color=\"white\", size=8)\n",
"p.line(x, y0, legend=\"y=x^2\", line_width=3)\n",
"p.line(x, y1, legend=\"y=10^x\", line_color=\"red\")\n",
"p.circle(x, y1, legend=\"y=10^x\", fill_color=\"red\", line_color=\"red\", size=6)\n",
"p.line(x, y2, legend=\"y=10^x^2\", line_color=\"orange\", line_dash=\"4 4\")\n",
"\n",
"# show the results\n",
"show(p)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"
"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## FOLIUM"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[folium](https://github.com/wrobstory/folium) has been also been developed by [Rob Story](http://wrobstory.github.io/) to provide an interface to the [leaflet.js](http://leafletjs.com/) JavaScript mapping library"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"an example of what it can do is available at: \n",
" \n",
"[https://rawgit.com/nicolasfauchereau/PLUVAR/master/www/index.html](https://rawgit.com/nicolasfauchereau/PLUVAR/master/www/index.html)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.1"
},
"latex_envs": {
"bibliofile": "biblio.bib",
"cite_by": "apalike",
"current_citInitial": 1,
"eqLabelWithNumbers": true,
"eqNumInitial": 0
}
},
"nbformat": 4,
"nbformat_minor": 0
}