Bokeh is an open-source library for creating interactive visualization for modern web browsers.
With Bokeh, you can use Python to build beautiful data visualizations, ranging from simple plots to complex dashboards with streaming datasets. In a nutshell: Bokeh lets you create JavaScript-powered visualizations without having to write any JavaScript yourself.
Bokeh can generate stand-alone HTML objects to use in any kind of website, or you can run Bokeh as a server. But Bokeh also works directly in Jupyter Notebooks.
Run the two notebook cells below to see Bokeh in action:
# activate Bokeh output in Jupyter notebook
from bokeh.io import output_notebook
output_notebook()
# create a complex chart with mouse-over tooltips
from bokeh.palettes import HighContrast3
from bokeh.plotting import figure, show
fruits = ["Apples", "Pears", "Nectarines", "Plums", "Grapes", "Strawberries"]
years = ["2015", "2016", "2017"]
data = {"fruits": fruits, "2015": [2, 1, 4, 3, 2, 4], "2016": [5, 3, 4, 2, 4, 6], "2017": [3, 2, 4, 4, 5, 3]}
p = figure(x_range=fruits, height=250, title="Fruit Counts by Year", toolbar_location=None, tools="hover", tooltips="$name @fruits: @$name")
p.vbar_stack(years, x="fruits", width=0.9, color=HighContrast3, source=data, legend_label=years)
p.y_range.start = 0
p.x_range.range_padding = 0.1
p.xgrid.grid_line_color = None
p.axis.minor_tick_line_color = None
p.outline_line_color = None
p.legend.location = "top_left"
p.legend.orientation = "horizontal"
show(p)
This tutorial is an interactive way to learn the basics of Bokeh. This tutorial uses Bokeh's tight integration with Jupyter notebooks.
In the course of this tutorial, you will learn everything you need to know about Bokeh to build an interactive dashboard using the "T-100 Domestic Market" dataset of airline routes within the United States for the year 2021.
👇 Run the code cell below to see the dashboard you'll be building:
# load and display tutorial dashboard
from tutorial_dashboard import dashboard_layout
show(dashboard_layout)
This dashboard might take a few seconds to load. Once it is loaded, you can interact with the different elements of the dashboard.
The tutorial will walk you through all the steps of creating this dashboard, introducing you to Bokeh's most important concepts and functionalities. The skills you will learn in this tutorial will provide you with a solid foundation to build different kinds of Bokeh visualization.
You can also jump directly to any section of the tutorial to learn more about a specific aspect of Bokeh. Use the following links:
You can always access this table of contents using the link in the top right corner of every chapter!
This tutorial is a series of Jupyter notebooks. Each notebook contains two kinds of cells:
In some code cells, you will find instructions to modify the code. These instructions are marked with a comment that starts with 🔁. For example:
# 🔁 Modify the string for title below to change the title of the plot
plot = figure(title="Please change this title")
plot.scatter([1, 2, 3], [6, 7, 4], size=10, marker="circle")
show(plot)
After you have modified the code, please run the cell again. You will then see the results right underneath that cell.
At the bottom of each notebook, you will find a link to the next chapter in the tutorial. When you open a new chapter, all code cells will be in their initial state. Run each code cell as you make your way through each chapter.
Please run the code cells in the order they are presented in the notebooks. If you don't run the code cells in the correct order, you might get errors.
This tutorial is designed for people who are new to Bokeh. While this is a beginner tutorial, there are some basic concepts that will be helpful to know before you start:
Note: This tutorial is focused on Bokeh. For clarity and brevity, most of the data
processing necessary for the plots in this tutorial is done with pandas in a separate
Python script.
This tutorial will reference the data preparation script but will not go into detail
about the data preparation itself.
You can find the data processing code in carriers_data.py
.
This tutorial is designed to run on mybinder.org. You can also run this tutorial locally on your computer. See README.md for instructions.
There are several resources that go beyond the scope of this tutorial:
comprehensive guide to all aspects of Bokeh.
detailed reference of all Bokeh models and functions.
of examples that show how to use Bokeh to create different kinds of plots.
You will see the user guide, reference guide, and gallery referenced throughout this tutorial.
There are also many other resources that you might find helpful:
quick, high-level introduction to Bokeh.
to ask questions and discuss Bokeh.
resource for developers who want to contribute to Bokeh.
In the next section, you will learn how to install Bokeh and set up your environment.
Let's get started!