Reader small image

You're reading from  The Data Visualization Workshop

Product typeBook
Published inJul 2020
Reading LevelIntermediate
PublisherPackt
ISBN-139781800568846
Edition1st Edition
Languages
Tools
Right arrow
Authors (2):
Mario Döbler
Mario Döbler
author image
Mario Döbler

Mario Döbler is a Ph.D. student with a focus on deep learning at the University of Stuttgart. He previously interned at the Bosch Center for artificial intelligence in the Silicon Valley in the field of deep learning. He used state-of-the-art algorithms to develop cutting-edge products. In his master thesis, he dedicated himself to applying deep learning to medical data to drive medical applications.
Read more about Mario Döbler

Tim Großmann
Tim Großmann
author image
Tim Großmann

Tim Großmann is a computer scientist with interest in diverse topics, ranging from AI and IoT to Security. He previously worked in the field of big data engineering at the Bosch Center for Artificial Intelligence in Silicon Valley. In addition to that, he worked on an Eclipse project for IoT device abstractions in Singapore. He's highly involved in several open-source projects and actively speaks at tech meetups and conferences about his projects and experiences.
Read more about Tim Großmann

View More author details
Right arrow

6. Making Things Interactive with Bokeh

Overview

In this chapter, we will design interactive plots using the Bokeh library. By the end of this chapter, you will be able to use Bokeh to create insightful web-based visualizations and explain the difference between two interfaces for plotting. You will identify when to use the Bokeh server and create interactive visualizations.

Introduction

Bokeh is an interactive visualization library focused on modern browsers and the web. Other than Matplotlib or geoplotlib, the plots and visualizations we are going to create in this chapter will be based on JavaScript widgets. Bokeh allows us to create visually appealing plots and graphs nearly out of the box without much styling. In addition to that, it helps us construct performant interactive dashboards based on large static datasets or even streaming data.

Bokeh has been around since 2013, with version 1.4.0 being released in November 2019. It targets modern web browsers to present interactive visualizations to users rather than static images. The following are some of the features of Bokeh:

  • Simple visualizations: Through its different interfaces, it targets users of many skill levels, providing an API for quick and straightforward visualizations as well as more complex and extremely customizable ones.
  • Excellent animated visualizations: It provides...

Basic Plotting

As mentioned before, the plotting interface of Bokeh gives us a higher-level abstraction, which allows us to quickly visualize data points on a grid.

To create a new plot, we have to define our imports to load the necessary dependencies:

# importing the necessary dependencies
import pandas as pd
from bokeh.plotting import figure, show
from bokeh.io import output_notebook
output_notebook()

Before we can create a plot, we need to import the dataset. In the examples in this chapter, we will work with a computer hardware dataset. It can be imported by using pandas' read_csv method.

# loading the Dataset with pandas
dataset = pd.read_csv('../../Datasets/computer_hardware.csv')

The basic flow when using the plotting interface is comparable to that of Matplotlib. We first create a figure. This figure is then used as a container to define elements and call methods on:

# adding an index column to use it for the x-axis
dataset['index&apos...

Adding Widgets

One of the most powerful features of Bokeh is the ability to use widgets to interactively change the data that's displayed in a visualization. To understand the importance of interactivity in your visualizations, imagine seeing a static visualization about stock prices that only shows data for the last year.

If you're interested in seeing the current year or even visually comparing it to the recent and coming years, static plots won't be suitable. You would need to create one plot for every year or even overlay different years on one visualization, which would make it much harder to read.

Comparing this to a simple plot that lets the user select the date range they want, we can already see the advantages. You can guide the user by restricting values and only displaying what you want them to see. Developing a story behind your visualization is very important, and doing this is much easier if the user has ways of interacting with the data.

Bokeh...

Summary

In this chapter, we have looked at another option for creating visualizations with a whole new focus: web-based Bokeh plots. We also discovered ways in which we can make our visualizations more interactive and give the user the chance to explore data in a different way.

As we mentioned in the first part of this chapter, Bokeh is a comparably new tool that empowers developers to use their favorite language to create easily portable visualizations for the web. After working with Matplotlib, Seaborn, geoplotlib, and Bokeh, we can see some standard interfaces and similar ways to work with those libraries. After studying the tools that are covered in this book, it will be simple to understand new plotting tools.

In the next and final chapter, we will introduce a new real-life dataset to create visualizations. This last chapter will allow you to consolidate the concepts and tools that you have learned about in this book and further enhance your skills.

...
lock icon
The rest of the chapter is locked
You have been reading a chapter from
The Data Visualization Workshop
Published in: Jul 2020Publisher: PacktISBN-13: 9781800568846
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (2)

author image
Mario Döbler

Mario Döbler is a Ph.D. student with a focus on deep learning at the University of Stuttgart. He previously interned at the Bosch Center for artificial intelligence in the Silicon Valley in the field of deep learning. He used state-of-the-art algorithms to develop cutting-edge products. In his master thesis, he dedicated himself to applying deep learning to medical data to drive medical applications.
Read more about Mario Döbler

author image
Tim Großmann

Tim Großmann is a computer scientist with interest in diverse topics, ranging from AI and IoT to Security. He previously worked in the field of big data engineering at the Bosch Center for Artificial Intelligence in Silicon Valley. In addition to that, he worked on an Eclipse project for IoT device abstractions in Singapore. He's highly involved in several open-source projects and actively speaks at tech meetups and conferences about his projects and experiences.
Read more about Tim Großmann