{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n", " \n", " \n", " \n", " \n", "
\n", " \n", " \n", " \n", " \n", "

Bokeh Tutorial

\n", "
\n", "\n", "
Table of contents

01 Tutorial Overview

" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### What is Bokeh?\n", "\n", "Bokeh is an open-source library for creating **interactive visualization for modern web\n", "browsers**.\n", "\n", "With Bokeh, you can use Python to build beautiful data visualizations, ranging from\n", "simple plots to complex dashboards with streaming datasets.\n", "In a nutshell: Bokeh lets you create JavaScript-powered visualizations **without having\n", "to write any JavaScript yourself**.\n", "\n", "Bokeh can generate\n", "[stand-alone HTML objects](http://docs.bokeh.org/en/latest/docs/user_guide/embed.html)\n", "to use in any kind of website, or you can run Bokeh as a\n", "[server](http://docs.bokeh.org/en/latest/docs/user_guide/server.html).\n", "But Bokeh also works directly in Jupyter Notebooks.\n", "\n", "Run the two notebook cells below to see Bokeh in action:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# activate Bokeh output in Jupyter notebook\n", "from bokeh.io import output_notebook\n", "\n", "output_notebook()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# create a complex chart with mouse-over tooltips\n", "\n", "from bokeh.palettes import HighContrast3\n", "from bokeh.plotting import figure, show\n", "\n", "fruits = [\"Apples\", \"Pears\", \"Nectarines\", \"Plums\", \"Grapes\", \"Strawberries\"]\n", "years = [\"2015\", \"2016\", \"2017\"]\n", "\n", "data = {\"fruits\": fruits, \"2015\": [2, 1, 4, 3, 2, 4], \"2016\": [5, 3, 4, 2, 4, 6], \"2017\": [3, 2, 4, 4, 5, 3]}\n", "\n", "p = figure(x_range=fruits, height=250, title=\"Fruit Counts by Year\", toolbar_location=None, tools=\"hover\", tooltips=\"$name @fruits: @$name\")\n", "\n", "p.vbar_stack(years, x=\"fruits\", width=0.9, color=HighContrast3, source=data, legend_label=years)\n", "\n", "p.y_range.start = 0\n", "p.x_range.range_padding = 0.1\n", "p.xgrid.grid_line_color = None\n", "p.axis.minor_tick_line_color = None\n", "p.outline_line_color = None\n", "p.legend.location = \"top_left\"\n", "p.legend.orientation = \"horizontal\"\n", "\n", "show(p)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### What's in this tutorial?\n", "\n", "This tutorial is an **interactive way to learn the basics of Bokeh**. This tutorial uses\n", "[Bokeh's tight integration](http://docs.bokeh.org/en/latest/docs/user_guide/jupyter.html)\n", "with Jupyter notebooks.\n", "\n", "In the course of this tutorial, you will learn everything you need to know about Bokeh\n", "to build an interactive dashboard using the\n", "[\"T-100 Domestic Market\"](https://transtats.bts.gov/DL_SelectFields.aspx?gnoyr_VQ=FIL&QO_fu146_anzr=Nv4%20Pn44vr45)\n", "dataset of airline routes within the United States for the year 2021.\n", "\n", "

\n", "👇 Run the code cell below to see the dashboard you'll be building:\n", "

" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# load and display tutorial dashboard\n", "from tutorial_dashboard import dashboard_layout\n", "\n", "show(dashboard_layout)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This dashboard **might take a few seconds to load**. Once it is loaded, you can interact\n", "with the different elements of the dashboard.\n", "\n", "The tutorial will walk you through all the steps of creating this dashboard, introducing\n", "you to Bokeh's most important concepts and functionalities.\n", "The skills you will learn in this tutorial will provide you with a solid\n", "foundation to build different kinds of Bokeh visualization.\n", "\n", "You can also jump directly to any section of the tutorial to learn more about a specific\n", "aspect of Bokeh.\n", "Use the following links:\n", "\n", "* 01 Introduction\n", "* [02 Bokeh installation and setup](02_installation_and_setup.ipynb)\n", "* [03 Basic concepts](03_basic_concepts.ipynb)\n", "* [04 Basic plotting](04_basic_plots.ipynb)\n", "* [05 Styling plots](05_styling.ipynb)\n", "* [06 Data sources](06_data_sources.ipynb)\n", "* [07 Adding annotations](07_annotations.ipynb)\n", "* [08 Plot tools and tooltips](08_plot_tools.ipynb)\n", "* [09 More plot types](09_more_plot_types.ipynb)\n", "* [10 Layouts](10_layouts.ipynb)\n", "* [11 Widgets and interactivity](11_widgets_interactivity.ipynb)\n", "* [12 Building the demo dashboard](12_demo_dashboard.ipynb)\n", "* [13 Exporting and embedding](13_exporting_embedding.ipynb)\n", "* [14 Next steps](15_next_steps.ipynb)\n", "\n", "You can always access this table of contents using the link in the top right corner of\n", "every chapter!" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### How do I use this tutorial?\n", "\n", "This tutorial is a series of Jupyter notebooks.\n", "Each notebook contains two kinds of cells:\n", "\n", "* **Text cells**, which contain text and images\n", "* **Code cells**, which contain Python code that you can run. \n", " You can also modify the code and run it again.\n", "\n", "In some code cells, you will find instructions to modify the code.\n", "These instructions are **marked with a comment that starts with 🔁**.\n", "For example:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# 🔁 Modify the string for title below to change the title of the plot\n", "plot = figure(title=\"Please change this title\")\n", "\n", "plot.scatter([1, 2, 3], [6, 7, 4], size=10, marker=\"circle\")\n", "show(plot)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "After you have modified the code, please run the cell again. You will then see the\n", "results right underneath that cell.\n", "\n", "At the bottom of each notebook, you will find a **link to the next chapter in the tutorial**.\n", "When you open a new chapter, all code cells will be in their initial state.\n", "Run each code cell as you make your way through each chapter.\n", "\n", "Please **run the code cells in the order they are presented** in the notebooks. If you\n", "don't run the code cells in the correct order, you might get errors." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### What do I need to know to use this tutorial?\n", "\n", "This tutorial is designed for people who are new to Bokeh. While this is a beginner\n", "tutorial, there are some basic concepts that will be helpful to know before you start:\n", "\n", "* Bokeh is a Python library. You will need to know some **basic Python** to use this\n", " tutorial. This includes:\n", " - Python functions\n", " - Python data types (str, int, float, dicts, lists, etc.)\n", " - Basic data operations (slicing, indexing, etc.)\n", " - Python classes\n", "* Bokeh is a data visualization library. It will help to have **basic knowledge of\n", " [pandas](https://pandas.pydata.org/)**, specifically the concept of a \n", " [DataFrame](https://pandas.pydata.org/pandas-docs/stable/getting_started/intro_tutorials/01_table_oriented.html#min-tut-01-tableoriented).\n", "* This tutorial uses Jupyter notebooks. Therefore, some **basic knowledge of how to use\n", " Jupyter notebooks** is helpful. You can find a quick introduction to Jupyter\n", " notebooks in the [Jupyter documentation](https://jupyter-notebook.readthedocs.io/en/stable/notebook.html).\n", "* Bokeh runs in the browser, using JavaScript. Knowledge of JavaScript is not\n", " required to use Bokeh and this tutorial. However, a basic knowledge of JavaScript\n", " will be helpful in understanding some of the more advanced concepts you'll find\n", " here.\n", "\n", "Note: This tutorial is focused on Bokeh. For clarity and brevity, most of the data\n", "processing necessary for the plots in this tutorial is done with pandas in a separate\n", "Python script.\n", "This tutorial will reference the data preparation script but will not go into detail\n", "about the data preparation itself.\n", "You can find the data processing code in [`carriers_data.py`](../data/carriers_data.py).\n", "\n", "This tutorial is designed to run on [mybinder.org](https://mybinder.readthedocs.io/en/latest/).\n", "You can also run this tutorial locally on your computer.\n", "See [README.md](../README.md) for instructions." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Where can I find more help and information?\n", "\n", "There are several resources that go beyond the scope of this tutorial:\n", "\n", "* [**Bokeh user guide**](http://docs.bokeh.org/en/latest/docs/user_guide.html): A\n", "comprehensive guide to all aspects of Bokeh.\n", "* [**Bokeh reference guide**](http://docs.bokeh.org/en/latest/docs/reference.html): A\n", "detailed reference of all Bokeh models and functions.\n", "* [**Bokeh gallery**](http://docs.bokeh.org/en/latest/docs/gallery.html): A collection\n", "of examples that show how to use Bokeh to create different kinds of plots.\n", "\n", "You will see the user guide, reference guide, and gallery referenced throughout this\n", "tutorial.\n", "\n", "There are also many other resources that you might find helpful:\n", "\n", "* [**Bokeh first steps**](http://docs.bokeh.org/en/latest/docs/first_steps.html): A\n", "quick, high-level introduction to Bokeh.\n", "* [**Bokeh discourse**](https://discourse.bokeh.org/): A forum for users and developers\n", "to ask questions and discuss Bokeh.\n", "* [**Bokeh developer guide**](http://docs.bokeh.org/en/latest/docs/dev_guide.html): A\n", "resource for developers who want to contribute to Bokeh." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Next section\n", "\n", "\n", " \"Next\n", "\n", "\n", "In the [next section](02_installation_and_setup.ipynb), you will learn how to install\n", "Bokeh and set up your environment.\n", "\n", "Let's get started!" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.12.0" }, "vscode": { "interpreter": { "hash": "0494a81e5f69860dcb844ce8e12eb9c88a7e813ddbfb0fbade72137f5ce45437" } } }, "nbformat": 4, "nbformat_minor": 4 }