Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
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

eBook
€8.99 €19.99
Paperback
€24.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
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.

Who is this book for?

This book is well suited for data scientists and data analysts who want to perform interactive data visualization on their web browsers using Bokeh. Some exposure to Python programming will be helpful, but prior experience with Bokeh is not required.

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

Product Details

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

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

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

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 79.97
Hands-On Data Analysis with NumPy and pandas
€24.99
Hands-On Data Visualization with Bokeh
€24.99
Hands-On Data Science with Anaconda
€29.99
Total 79.97 Stars icon
Banner background image

Table of Contents

9 Chapters
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

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.7
(6 Ratings)
5 star 50%
4 star 0%
3 star 33.3%
2 star 0%
1 star 16.7%
Filter icon Filter
Top Reviews

Filter reviews by




jose Aug 05, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Easy to follow
Amazon Verified review Amazon
R. Millikan Sep 26, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This is a really good book for getting someone started with Bokeh. Their is soooo much more to learn, but it is a very good start
Amazon Verified review Amazon
Hernán Díaz Dec 28, 2020
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Muy buen libro, es un poco corto pero va directo al grano con lo importante y te enseña lo suficiente para que se pueda continuar por uno mismo
Amazon Verified review Amazon
John Coleman May 06, 2019
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
The book is a quick read and is useful for getting up and running with Bokeh, but it is woefully incomplete and has some occasional technical errors.As a glaring example of the incompleteness, the book gives very, very little guidance about the handling of color (which is a major topic in any graphing library). It illustrates uses of color words such as color = 'red' , but has no discussion of issues like: which color words can you use? Where can you find a list? How could you specify a color using RGB or HSL or color hex strings? It illustrates CategoricalColorMapper (applied to a hard-wired two color palette) but has zero discussion or even mention of LinearColorMapper and LogColorMapper for continuous data or other options for color palettes (such as the rich built-in set of palettes). And even though it mentions color mapping, it doesn't say anything at all about color bars which provide a legend for the meaning of colors. These are all things I had to learn on my own from other sources (such as Stack Overflow) while reading this book. There were numerous other cases where relatively basic questions which naturally arose when reading the book were left unanswered in the book itself. I have illustrated the incompleteness with color, but I could also mention e.g. tools. It has a decent but still incomplete discussion of hover tools but its discussion of other tools ranges from nonexistent to cursory.As far as technical errors, there aren't too many but there are some. For example, on page 25 it says that "You can also add labels to the x- and y-axis by using the following code: plot.figure(x_axis_label = ..." but -- you can't. Using the author's code yields AttributeError: 'Figure' object has no attribute 'figure'. The fix isn't hard -- but is to be found on Stack Overflow (or the online documentation) rather than the book itself.On the plus side, the book does a good job in explaining how Bokeh plays nicely with pandas and numpy and is reasonably well written. For this reason, it deserves more than one or two stars. If you want a quick start which will give you a basic orientation to Bokeh in just a few days, I recommend this book. But, if you want to learn to make sophisticated graphs with Bokeh, this isn't your guide.
Amazon Verified review Amazon
SJ Oct 10, 2018
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
This book gives a quick intro to bokeh. It does not go indepth into the more complex uses of bokeh. You should really use this in conjunction with the online bokeh.pydata.org resource to fill out the missing pieces etc. Because I like to know the structure of the data I am using and the data structure required by various 'platforms', it would have been helpful if samples of the data sets used eg the SP500 data were given. This data is given in a separate chapter at the end, but as the tech requirements are always repeated at the beginning of each chapter and section, I dont see why sample data structure cannot also be shown. This would give the reader a better appreciation for the method and arguments used. The book is also a little thin on graphing networks and geo data, hopefully the next edition might beef up this chapter considerably. I give this an average rating.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.