Skip to content

Commit 8c3bf37

Browse files
authored
Move appendix content in to primary notebbok flow (#31)
Signed-off-by: Pavithra Eswaramoorthy <[email protected]>
1 parent 87b9f4b commit 8c3bf37

9 files changed

+281
-411
lines changed

notebooks/01_introduction.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
"[\"T-100 Domestic Market\"](https://transtats.bts.gov/DL_SelectFields.aspx?gnoyr_VQ=FIL&QO_fu146_anzr=Nv4%20Pn44vr45)\n",
105105
"dataset of airline routes within the United States for the year 2021.\n",
106106
"\n",
107-
"<p style=\"background-color: #f74531; padding: 10px;\">\n",
107+
"<p style=\"background-color: #FFCCCC; padding: 10px;\">\n",
108108
"👇 Run the code cell below to see the dashboard you'll be building:\n",
109109
"</p>"
110110
]

notebooks/07_annotations.ipynb

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,122 @@
491491
"By default, the ScaleBar uses metric length units, but you can define custom units of measurement using the `CustomDimensional` model. This allows you to create scale bars with units such as angular measurements or any other custom units you might need. To learn more about customizing units and other advanced features of the ScaleBar, refer to the [Bokeh User Guide on Annotations](https://docs.bokeh.org/en/latest/docs/user_guide/basic/annotations.html#scale-bars)."
492492
]
493493
},
494+
{
495+
"cell_type": "markdown",
496+
"metadata": {},
497+
"source": [
498+
"### LaTeX"
499+
]
500+
},
501+
{
502+
"cell_type": "markdown",
503+
"metadata": {},
504+
"source": [
505+
"Bokeh supports LaTeX equations in a number of different elements.\n",
506+
"\n",
507+
"This is based on the [Bessel equation example](https://docs.bokeh.org/en/latest/docs/examples/styling/mathtext/latex_bessel.html) in the Bokeh documentation:"
508+
]
509+
},
510+
{
511+
"cell_type": "code",
512+
"execution_count": null,
513+
"metadata": {},
514+
"outputs": [],
515+
"source": [
516+
"# from bokeh.io import output_notebook\n",
517+
"# from bokeh.models import ColorBar, CustomJS, Div, FixedTicker, Label, LinearColorMapper, Paragraph, Slider\n",
518+
"from bokeh.palettes import TolPRGn, PiYG\n",
519+
"# from bokeh.plotting import column, figure, show\n",
520+
"import numpy as np\n",
521+
"from scipy.special import jv"
522+
]
523+
},
524+
{
525+
"cell_type": "code",
526+
"execution_count": null,
527+
"metadata": {},
528+
"outputs": [],
529+
"source": [
530+
"p = figure(\n",
531+
" width=700, height=450,\n",
532+
" title=r\"$$\\text{Bessel functions of the first kind: } J_\\alpha(x) = \\sum_{m=0}^{\\infty}\"\n",
533+
" r\"\\frac{(-1)^m}{m!\\:\\Gamma(m+\\alpha+1)} \\left(\\frac{x}{2}\\right)^{2m+\\alpha}$$\",\n",
534+
")\n",
535+
"p.x_range.range_padding = 0\n",
536+
"p.xaxis.axis_label = r\"$$x$$\"\n",
537+
"p.yaxis.axis_label = r\"$$J_\\alpha(x)$$\"\n",
538+
"p.title.text_font_size = \"14px\"\n",
539+
"\n",
540+
"x = np.linspace(0.0, 14.0, 100)\n",
541+
"\n",
542+
"for i, (xlabel, ylabel) in enumerate(zip([0.5, 1.6, 2.8, 4.2], [0.95, 0.6, 0.5, 0.45])):\n",
543+
" p.line(x, jv(i, x), line_width=3, color=PiYG[4][i])\n",
544+
" p.add_layout(Label(text=r\"$$J_\" + str(i) + \"(x)$$\", x=xlabel, y=ylabel))\n",
545+
"\n",
546+
"show(p)"
547+
]
548+
},
549+
{
550+
"cell_type": "markdown",
551+
"metadata": {},
552+
"source": [
553+
"Note:\n",
554+
"\n",
555+
"- Use of standard LaTeX delimeters of ``$$``. Other options are available.\n",
556+
"- Use raw Python strings e.g. ``r\"$$\\alpha$$\"`` so that backslashes are interpreted as normal characters rather than control sequences. \n",
557+
"- ``Div`` and ``Paragraph`` accept LaTeX for just part of their contents, but for all other elements the whole contents must be LaTeX.\n",
558+
" - To put normal text in a LaTeX string use ``\\text{...}``.\n",
559+
" - We are actively working on improvements in this area.\n",
560+
"\n",
561+
"\n",
562+
"#### Where can LaTeX be used?"
563+
]
564+
},
565+
{
566+
"cell_type": "code",
567+
"execution_count": null,
568+
"metadata": {},
569+
"outputs": [],
570+
"source": [
571+
"from bokeh.models import ColorBar, Div, FixedTicker, LinearColorMapper, Paragraph, Slider\n",
572+
"from bokeh.plotting import column"
573+
]
574+
},
575+
{
576+
"cell_type": "code",
577+
"execution_count": null,
578+
"metadata": {},
579+
"outputs": [],
580+
"source": [
581+
"p = figure(width=500, height=400)\n",
582+
"p.scatter(1, 1, size=0)\n",
583+
"\n",
584+
"p.title = r\"$$\\LaTeX \\text{ figure title}$$\"\n",
585+
"p.axis.axis_label = r\"$$\\LaTeX \\text{ axis label}$$\"\n",
586+
"p.axis.ticker = FixedTicker(ticks=[1])\n",
587+
"p.axis.major_label_overrides = {1: r\"$$\\LaTeX \\text{ tick label}$$\"}\n",
588+
"p.yaxis.major_label_orientation = \"vertical\"\n",
589+
"p.add_layout(Label(text=r\"$$\\LaTeX \\text{ label}$$\", text_font_size=\"26px\",\n",
590+
" angle=0.4, text_baseline=\"middle\", text_align=\"center\", x=1, y=1))\n",
591+
"\n",
592+
"slider = Slider(start=0, end=100, value=50, step=1, title=r\"$$\\LaTeX \\text{ slider}$$\")\n",
593+
"div = Div(text=r\"$$\\LaTeX$$ div\")\n",
594+
"paragraph = Paragraph(text=r\"$$\\LaTeX$$ paragraph\")\n",
595+
"\n",
596+
"color_mapper = LinearColorMapper(palette=PiYG[8])\n",
597+
"colorbar = ColorBar(color_mapper=color_mapper, title=r\"$$\\LaTeX \\text{ colorbar title}$$\")\n",
598+
"p.add_layout(colorbar, \"right\")\n",
599+
"\n",
600+
"show(column(p, slider, div, paragraph))"
601+
]
602+
},
603+
{
604+
"cell_type": "markdown",
605+
"metadata": {},
606+
"source": [
607+
"For further information see the [LaTeX section](https://docs.bokeh.org/en/latest/docs/user_guide/styling/mathtext.html#latex) in the User Guide."
608+
]
609+
},
494610
{
495611
"cell_type": "markdown",
496612
"metadata": {},

notebooks/08_plot_tools.ipynb

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,96 @@
453453
"- `use_handles`: Set to `True` to add customizable interaction handles for moving (middle) and resizing (edges) the selection box."
454454
]
455455
},
456+
{
457+
"cell_type": "markdown",
458+
"metadata": {},
459+
"source": [
460+
"## Aside: WebGL"
461+
]
462+
},
463+
{
464+
"cell_type": "markdown",
465+
"metadata": {},
466+
"source": [
467+
"Bokeh draws graphics on web pages using HTML Canvas by default. For larger datasets there is another option which is to use WebGL. This provides hardware acceleration of graphics if you have a processor or graphics cards that supports it.\n",
468+
"\n",
469+
"Let's look at an example that compares Canvas and WebGL side-by-side, using a ``hex_tile`` plot which is 2D histogram using hexagons."
470+
]
471+
},
472+
{
473+
"cell_type": "code",
474+
"execution_count": null,
475+
"metadata": {},
476+
"outputs": [],
477+
"source": [
478+
"from bokeh.layouts import row\n",
479+
"from bokeh.plotting import figure, show\n",
480+
"from bokeh.transform import linear_cmap\n",
481+
"from bokeh.util.hex import hexbin\n",
482+
"import numpy as np"
483+
]
484+
},
485+
{
486+
"cell_type": "code",
487+
"execution_count": null,
488+
"metadata": {},
489+
"outputs": [],
490+
"source": [
491+
"n = 5_000_000\n",
492+
"x = np.random.standard_normal(n)\n",
493+
"y = np.random.standard_normal(n)\n",
494+
"\n",
495+
"bins = hexbin(x, y, 0.01)\n",
496+
"print(f\"Number of hexagons: {len(bins):,}\")"
497+
]
498+
},
499+
{
500+
"cell_type": "code",
501+
"execution_count": null,
502+
"metadata": {},
503+
"outputs": [],
504+
"source": [
505+
"ps = []\n",
506+
"for backend in ([\"canvas\", \"webgl\"]):\n",
507+
" p = figure(title=backend, tools=\"pan, wheel_zoom, box_select, reset\",\n",
508+
" output_backend=backend, width=450, height=450, lod_threshold=None)\n",
509+
" p.grid.visible = False\n",
510+
" p.hex_tile(q=\"q\", r=\"r\", size=1, line_color=None, source=bins,\n",
511+
" fill_color=linear_cmap('counts', 'Plasma256', 0, max(bins.counts)))\n",
512+
" ps.append(p)\n",
513+
"show(row(ps))"
514+
]
515+
},
516+
{
517+
"cell_type": "markdown",
518+
"metadata": {},
519+
"source": [
520+
"Interact with the plots to see how much faster WebGL is in your browser. Things to try:\n",
521+
"\n",
522+
"* Pan using the mouse\n",
523+
"* Zoom using the mouse wheel\n",
524+
"* Select a region of the plot such as one quarter of it, and repeat the pan and zoom"
525+
]
526+
},
527+
{
528+
"cell_type": "markdown",
529+
"metadata": {},
530+
"source": [
531+
"### How much faster is WebGL?\n",
532+
"\n",
533+
"It is difficult to generalize, it depends on the graphics processing hardware you have available. Try it out to see.\n",
534+
"\n",
535+
"### How do you enable WebGL?\n",
536+
"\n",
537+
"By using the ``output_backend=\"webgl\"`` keyword argument when creating a ``figure``.\n",
538+
"\n",
539+
"### What glyphs are supported by WebGL?\n",
540+
"\n",
541+
"Not all Bokeh glyphs have WebGL support yet, but we are adding more all the time. If you have chosen to use WebGL then Bokeh will use WebGL for the glyphs that it can, and drop back to using Canvas for those not yet supported.\n",
542+
"\n",
543+
"For a full list of glyphs supported using WebGL see the [latest Bokeh documentation](https://docs.bokeh.org/en/latest/docs/user_guide/output/webgl.html#supported-glyphs)"
544+
]
545+
},
456546
{
457547
"cell_type": "markdown",
458548
"metadata": {},

notebooks/09_more_plot_types.ipynb

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@
5252
"This chapter introduces **specialized plot types**:\n",
5353
"- [Map plots](#Map-plots)\n",
5454
"- [Wedge plots](#Wedge-plots) (pie and donut charts)\n",
55-
"- [Subplots](#Subplots)"
55+
"- [Subplots](#Subplots)\n",
56+
"- [Contour plots](#Contour-plots)"
5657
]
5758
},
5859
{
@@ -783,6 +784,68 @@
783784
"For additional examples of `subplot`, check out [polar_subcoordinates](https://docs.bokeh.org/en/latest/docs/examples/plotting/polar_subcoordinates.html) and [ridgeplot_subcoordinates](https://docs.bokeh.org/en/latest/docs/examples/plotting/ridgeplot_subcoordinates.html)."
784785
]
785786
},
787+
{
788+
"cell_type": "markdown",
789+
"metadata": {},
790+
"source": [
791+
"## Contour plots"
792+
]
793+
},
794+
{
795+
"cell_type": "markdown",
796+
"metadata": {},
797+
"source": [
798+
"Bokeh includes contour plots. You can plot both contour lines and filled regions between contour lines with a single ``contour`` call."
799+
]
800+
},
801+
{
802+
"cell_type": "code",
803+
"execution_count": null,
804+
"metadata": {},
805+
"outputs": [],
806+
"source": [
807+
"from bokeh.palettes import Sunset"
808+
]
809+
},
810+
{
811+
"cell_type": "code",
812+
"execution_count": null,
813+
"metadata": {},
814+
"outputs": [],
815+
"source": [
816+
"# Data to contour is the sum of two Gaussian functions.\n",
817+
"x, y = np.meshgrid(np.linspace(0, 3, 40), np.linspace(0, 2, 30))\n",
818+
"z = 1.3*np.exp(-2.5*((x-1.3)**2 + (y-0.8)**2)) - 1.2*np.exp(-2*((x-1.8)**2 + (y-1.3)**2))"
819+
]
820+
},
821+
{
822+
"cell_type": "code",
823+
"execution_count": null,
824+
"metadata": {},
825+
"outputs": [],
826+
"source": [
827+
"p = figure(width=700, height=400, x_range=(0, 3), y_range=(0, 2))\n",
828+
"\n",
829+
"levels = np.linspace(-1, 1, 9)\n",
830+
"contour_renderer = p.contour(x, y, z, levels, fill_color=Sunset, line_color=\"black\")\n",
831+
"\n",
832+
"colorbar = contour_renderer.construct_color_bar()\n",
833+
"p.add_layout(colorbar, \"right\")\n",
834+
"\n",
835+
"show(p)"
836+
]
837+
},
838+
{
839+
"cell_type": "markdown",
840+
"metadata": {},
841+
"source": [
842+
"Contour lines are calculated and displayed if ``line_color`` is something other than ``None``, and filled contour regions are calculated and displayed if ``fill_color`` is something other than ``None``.\n",
843+
"\n",
844+
"Visual properties (``line``, ``fill`` and ``hatch``) can be specified as scalar or vector properties as usual, such as ``line_width`` and ``hatch_pattern``.\n",
845+
"\n",
846+
"For more information see the Contour plots [topic guide](https://docs.bokeh.org/en/latest/docs/user_guide/topics/contour.html) in the latest Bokeh documentation."
847+
]
848+
},
786849
{
787850
"cell_type": "markdown",
788851
"metadata": {},

notebooks/11_widgets_interactivity.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@
497497
"\n",
498498
"div = Div(\n",
499499
" text=r\"\"\"\n",
500-
"<div style=\"background-color: darkolivegreen; padding:10px;\">\n",
500+
"<div style=\"background-color: lightgreen; padding:10px;\">\n",
501501
" <h2>Bokeh's Div widget</h2>\n",
502502
" <p> Bokeh's Div widget uses <a href=\"https://en.wikipedia.org/wiki/HTML\">HTML</a> to display text and other information.</p target=\"_blank\">\n",
503503
" <p> It is one of the elements that support <a href=\"https://docs.bokeh.org/en/latest/docs/user_guide/styling/mathtext.html\">LaTeX and MathML math expressions</a>. For example:</p target=\"_blank\">\n",

notebooks/13_exporting_embedding.ipynb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,15 @@
8787
"save(p)"
8888
]
8989
},
90+
{
91+
"cell_type": "markdown",
92+
"metadata": {},
93+
"source": [
94+
"<p style=\"background-color: #dddddd; padding: 10px;\">\n",
95+
" ✨ The HTML output file of the complete dashboard is hosted at: <a href=\"https://bokeh.github.io/tutorial/\">bokeh.github.io/tutorial ↗️</a>\n",
96+
"</p>"
97+
]
98+
},
9099
{
91100
"cell_type": "markdown",
92101
"metadata": {},

0 commit comments

Comments
 (0)