Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Hands-On Data Visualization with Bokeh
Hands-On Data Visualization with Bokeh

Hands-On Data Visualization with Bokeh: Interactive web plotting for Python using Bokeh

By Kevin Jolly
zł106.99 zł59.99
Book Jun 2018 174 pages 1st Edition
eBook
zł106.99 zł59.99
Print
zł133.99
Subscription
Free Trial
eBook
zł106.99 zł59.99
Print
zł133.99
Subscription
Free Trial

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Buy Now

Product Details


Publication date : Jun 15, 2018
Length 174 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781789135404
Category :
Table of content icon View table of contents Preview book icon Preview Book

Hands-On Data Visualization with Bokeh

Bokeh Installation and Key Concepts

Welcome to the world of interactive data visualization using the popular Bokeh library in Python. As you go through the chapter, you will learn about the following topics:

  • What exactly Bokeh is and how it differs from other plotting libraries
  • How you can install Bokeh on your local machine
  • How to verify your Bokeh installation
  • Where you can go for help should things go wrong
  • Some key concepts regarding Bokeh's internal workings

Bokeh is an interactive data visualization library in Python that helps users across all levels visualize both simple and complex data from datasets ranging from small to big. You can use Bokeh to create both interactive plots and applications that speak to the general public, statisticians, and even business leaders!

Technical requirements

The difference between static and interactive plotting

In the world of data visualization, there are three main libraries using Python that dominate the market, and these are as follows:

  • Matplotlib
  • Seaborn
  • Bokeh

The first two, Matplotlib and Seaborn, let you plot static plots—plots that do not change and plots that cannot be interacted with. These plots are useful and add value when performing exploratory data analysis, as they are quick and easy to implement and very fast to execute.

The third plotting library, Bokeh, lets you plot interactive plots—plots that change when the user interacts with them. These plots are useful when you want to give your audience a wide range of options and tools for inferring and looking at data from various angles.

Installing the Bokeh library

Bokeh has a few dependencies. In order to use Bokeh, ensure that the following packages are already installed:

  • NumPy
  • Jinja2
  • Six
  • Requests
  • Tornado >= 4.0
  • PyYaml
  • DateUtil

If you're using Python 2.7, ensure that you have all the afore mentioned packages along with:

  • Futures

Installing Bokeh using a Python distribution

If you have all of your Python packages installed and managed using a distribution such as Anaconda, you can install Bokeh using your Bash Terminal or a Windows Prompt using the following code:

conda install bokeh

You can also install Bokeh using PyPi for Python 2 via the following code:

pip install bokeh

You can install Bokeh using PyPi for Python 3 via the following code:

pip3 install bokeh

For the purposes of this book, all plots will be rendered using Bokeh Version 0.12.15. If you already have Bokeh installed and require an update, simply enter the following code in your terminal or shell:

sudo pip3 install bokeh --upgrade

Verifying your installation

Once you have installed Bokeh, you will want to verify that it is correctly installed. In order to verify the installation and create all your Bokeh plots, you'll need a Jupyter Notebook. If you are not familiar with working with a Jupyter Notebook before or have installed, the following link will provide you with a step-by-step tutorial on how to install and work with Jupyter Notebook: http://jupyter.org/install.

You can verify your installation of Bokeh by generating a simple line plot using a Jupyter Notebook with the following code:

from bokeh.plotting import figure, output_file, show

#HTML file to output your plot into
output_file("bokeh.html")

#Constructing a basic line plot

x = [1,2,3]
y = [4,5,6]

p = figure()

p.line(x,y)

show(p)

This should open up a new tab on your browser with a plot illustrated as follows:

Don't worry too much about what the code does for now. If you have got the preceding plot, you should be satisfied that Bokeh has been successfully installed on your local machine.

When things go wrong

In the event that things go wrong with your installation, you have the following two options:

  • The Bokeh mailing list (https://groups.google.com/a/anaconda.com/forum/#!forum/bokeh) is a group on Google that posts questions and queries related to Bokeh, which are then answered by experts who use the package on a regular basis. Joining this group or looking through its frequently asked questions should help you find the answer to your solution.
  • You can also submit an issue on the Bokeh GitHub issue tracker (https://github.com/bokeh/bokeh/issues); your issue will usually be solved in within a matter of a few hours, up to a few days.

Key concepts and the building blocks of Bokeh

While going through this book, you will come across some terms that are fundamental to understanding the Bokeh package. This section will take you through them.

The following are some key definitions related to Bokeh:

  • Application: The Bokeh application is a rendered Bokeh document that runs in the browser
  • Glyphs: Glyphs are the building blocks of Bokeh, and they are the lines, circles, rectangles, and other shapes that you see on a Bokeh plot
  • Server: The Bokeh server is used to share and publish interactive plots and apps to an audience of your choice
  • Widgets: Widgets in Bokeh are the sliders, drop-down menus, and other small tools that you can embed into your plot to add some interactivity

Plot outputs

There are two methods you can use to render your plot:

  • output_file: This method is used to output your plot as an HTML file and can be used as illustrated in the following code:
output_file('plot.html')
  • output_notebook: This is used to output your plot in the Jupyter Notebook you are presently working on and can be used as illustrated in the following code:
output_notebook()

Interfaces:

The first step to understanding interfaces is to understand what a class and a method are. Think of a class as a vessel that holds different types of cookie together. The vessel in this case is the class and the cookies are the methods that give the vessel some functionality, in our case, as a container for the cookies.

Since Python is an object-oriented programming language, it uses classes to group different objects that it creates together.

A class by itself is useless unless it has some functionality associated with it. These functionalities are provided to classes by methods.

Bokeh provides a mid-level plotting interface, similar to that of matplotlib , which is known as bokeh.plotting. The main class in the bokeh.plotting interface is the Figure class, which includes methods for adding different kinds of glyphs to a plot.

A user can create a Figure object by using the figure function, as illustrated in the following code:

from bokeh.plotting import figure

# create a Figure object
p = figure(plot_width=500, plot_height=400, tools="pan,hover")

In Bokeh, the figure function, as illustrated in the preceding code, is used to initialize and store the contents of your plot. The variable p in the preceding code now holds information about the plot, including its height, width, and the kind of tools the plot will use. Since figure is our main class, methods such as line, circle, and so on can be added to our diagram in order to create the plot.

Summary

This chapter has given you the exact set of steps required for installing Bokeh on your local machine. It has also given you a glimpse of the key terms that you'll run into as you work your way through this book.

Now that Bokeh has been successfully installed on your local machine, you can open up a new Jupyter Notebook to work on your first plots with Bokeh!

In the next chapter, you will learn how to create your very first plot using glyphs; you'll see how it lays the foundation for plotting using Bokeh.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • A step by step approach to creating interactive plots with Bokeh
  • Go from installation all the way to deploying your very own Bokeh application
  • Work with a real time datasets to practice and create your very own plots and applications

Description

Adding a layer of interactivity to your plots and converting these plots into applications hold immense value in the field of data science. The standard approach to adding interactivity would be to use paid software such as Tableau, but the Bokeh package in Python offers users a way to create both interactive and visually aesthetic plots for free. This book gets you up to speed with Bokeh - a popular Python library for interactive data visualization. The book starts out by helping you understand how Bokeh works internally and how you can set up and install the package in your local machine. You then use a real world data set which uses stock data from Kaggle to create interactive and visually stunning plots. You will also learn how to leverage Bokeh using some advanced concepts such as plotting with spatial and geo data. Finally you will use all the concepts that you have learned in the previous chapters to create your very own Bokeh application from scratch. By the end of the book you will be able to create your very own Bokeh application. You will have gone through a step by step process that starts with understanding what Bokeh actually is and ends with building your very own Bokeh application filled with interactive and visually aesthetic plots.

What you will learn

Installing Bokeh and understanding its key concepts Creating plots using glyphs, the fundamental building blocks of Bokeh Creating plots using different data structures like NumPy and Pandas Using layouts and widgets to visually enhance your plots and add a layer of interactivity Building and hosting applications on the Bokeh server Creating advanced plots using spatial data

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Buy Now

Product Details


Publication date : Jun 15, 2018
Length 174 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781789135404
Category :

Table of Contents

10 Chapters
Preface Chevron down icon Chevron up icon
Bokeh Installation and Key Concepts Chevron down icon Chevron up icon
Plotting using Glyphs Chevron down icon Chevron up icon
Plotting with different Data Structures Chevron down icon Chevron up icon
Using Layouts for Effective Presentation Chevron down icon Chevron up icon
Using Annotations, Widgets, and Visual Attributes for Visual Enhancement Chevron down icon Chevron up icon
Building and Hosting Applications Using the Bokeh Server Chevron down icon Chevron up icon
Advanced Plotting with Networks, Geo Data, WebGL, and Exporting Plots Chevron down icon Chevron up icon
The Bokeh Workflow – A Case Study Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Filter icon Filter
Top Reviews
Rating distribution
Empty star icon Empty star icon Empty star icon Empty star icon Empty star icon 0
(0 Ratings)
5 star 0%
4 star 0%
3 star 0%
2 star 0%
1 star 0%

Filter reviews by


No reviews found
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.