Chapter 4 From Static To Interactive Visualization
Chapter 4 From Static To Interactive Visualization
Copyright © 2020 Packt Publishing, Inc. All Rights Reserved. This content is based on book Interactive Data
Visualization with Python: Present your data as an effective and compelling story, 2nd Edition Illustrated Edition, by
Abha Belorkar, Sharath Chandra Guntuku, Shubhangi Hora, Anshu Kumar.
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by
any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in
critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the
information presented. However, the information contained in this book is sold without warranty, either express or
implied. Neither the authors, nor Packt Publishing, and its dealers and distributors will be held liable for any damages
caused or alleged to be caused directly or indirectly by this book.
Outline
• Introduction
• Static versus Interactive Visualization
• Applications of Interactive Data Visualizations
• Interactive Data Visualization with Bokeh
• Creating the Base Static Plot for an Interactive
• Data Visualization
• Adding a Slider to the Static Plot
• Adding a Hover Tool
• Interactive Data Visualization with Plotly Express
• Creating an Interactive Scatter Plot
• Use Case 4: Creating Different Interactive Visualizations Using Plotly Express
From Static to Interactive Visualization
• We discussed static data visualizations in the previous chapter – graphs and plots that are stagnant and cannot be
modified or interacted with in real time by the audience.
• Interactive data visualizations are a step ahead of static ones.
• The definition of interactive is something that involves communication between two or more things or people
that work together.
• Therefore, interactive visualizations are graphical representations of analyzed data (static or dynamic) that can
react and respond to user actions in the moment.
https://www.omnisci.com/
From Static to Interactive Visualization
• The ability for a plot to provide you with more information about a datapoint
when there's a user action, such as your mouse hovering above it, is what makes
it interactive.
The only insight we can gain from this plot is the relationship between weight and sex – male clients visiting
this gym weigh between 62kg and 91kg, female clients weigh between 57kg and 86kg, and clients
identifying as other weigh between 61kg and 90kg. There is, however, a third feature present in the dataset
that's used to generate this box plot – age. Adding this feature to the preceding static plot may lead to confusion
in terms of understanding the data.
Static versus Interactive Visualization
Applications of Interactive Data Visualizations
Any industry that possesses large amounts of data can benefit from using interactive data visualizations.
Most popular forms of human input and interactive features
Slider: A slider allows the user to see data pertaining to a range of something. As the user changes the position of
the slider, the plot changes in real time. This allows the user to see several plots in real time:
2. Create a function called update_plot that will update the plot every time the slider is moved:
def update_plot(attr, old, new)
3. Apply the .on_change() function with value and update_plot as the parameters to tell the plot that once the
value of the slider changes, update the plot using the method described in the update_plot function.
slider.on_change('value', update_plot)
Creating the Base Static Plot for an Interactive Data Visualization
Adding a Hover Tool
To allow the user to hover above a datapoint on the plot to see the name of the country, the carbon dioxide
emissions, and the GDP:
Create a hover tool called hover:
creating an interactive data visualization with Plotly Express takes very few lines of code and the syntax is easy to
learn and use. Besides scatter plots, the library has many other types of plots that you can use to interactively
visualize different types of data.