09 Static To Interactive Visualisation
09 Static To Interactive Visualisation
Visualisation
Lecture 9
SLIDESMANIA.COM
Copyright © 2020, 2015, 2011 Pearson Education, Inc. All Rights Reserved
Copyright © 2020, Packt Publishing, Inc. All Rights Reserved 1
Learning Objectives
✓ Understand the categories and types of visualisation
✓ Learn different libraries of data visualisation
✓ Static to interactive visualisation
✓ Know the capabilities and limitations of different plots
SLIDESMANIA.COM
2
Visualisation Categories
✓ Exploration: helps find a story the data is telling you
Data exploration is the first step in data analysis involving the
use of statistical techniques to uncover data set characteristics
and initial patterns (outlier, unstructured, missing values, etc.).
Seaborn harnesses the power of matplotlib to create beautiful charts in a few lines of code. The key difference is
Seaborn’s default styles and color palettes, which are designed to be more aesthetically pleasing and modern. Since
Seaborn Seaborn is built on top of matplotlib, you’ll need to know matplotlib to tweak Seaborn’s defaults.
Like ggplot, Bokeh is based on The Grammar of Graphics, but unlike ggplot, it’s native to Python, not ported over
from R. Its strength lies in the ability to create interactive, web-ready plots, which can easily give the output as JSON
Bokeh objects, HTML documents, or interactive web applications. Bokeh also supports streaming and real-time data.
You might know Plotly as an online platform for data visualization, but did you also know you can access its
capabilities from a Python notebook? Like Bokeh, Plotly’s forte is making interactive plots, but it offers some charts
Plotly you won’t find in most libraries, like contour plots, dendograms, and 3D charts.
geoplotlib is a toolbox for creating maps and plotting geographical data. You can use it to create a variety of map-
types, like choropleths, heatmaps, and dot density maps. You must have Pyglet (an object-oriented programming
SLIDESMANIA.COM
Geoplotlib interface) installed to use geoplotlib. Nonetheless, since most Python data visualization libraries don’t offer maps, it’s
nice to have a library dedicated solely to them.
https://mode.com/blog/python-data-visualization-libraries/
Seaborn VS Matplotlib
SLIDESMANIA.COM
7
SLIDESMANIA.COM
Sample Visualisation
Pokemon dataset from:
https://github.com/LewBrace/da_and_vis_python
SLIDESMANIA.COM
Plotting a histogram
SLIDESMANIA.COM
Bins
There are a couple of ways to manipulate bins in matplotlib.
SLIDESMANIA.COM
Benefits of Seaborn
➢ Matplotlib is a powerful, but sometimes unwieldy, Python library.
➢ Seaborn provides a high-level interface to Matplotlib and makes it easier to
produce graphs like the one on the right.
➢ Some IDEs incorporate elements of this “under the hood” nowadays.
➢ Seaborn offers:
- Using default themes that are aesthetically pleasing.
- Setting custom colour palettes.
- Making attractive statistical plots.
- Easily and flexibly displaying distributions.
- Visualising information from matrices and DataFrames.
➢ The last three points have led to Seaborn becoming the exploratory data
SLIDESMANIA.COM
Colour by stage.
Separate by stage.
Generate using a swarmplot.
Rotate axis on x-ticks by 45 degrees.
SLIDESMANIA.COM
Seaborn: A box plot
▪ The total, stage, and legendary entries are not combat stats so we
should remove them.
▪ Pandas makes this easy to do, we just create a new dataframe
▪ We just use Pandas’ .drop() function to create a dataframe that
doesn’t include the variables we don’t want.
SLIDESMANIA.COM
Seaborn: Violin plots
▪ Violin plots are useful alternatives to box plots.
▪ They show the distribution of a variable through the thickness of the violin.
▪ Here, we visualise the distribution of attack by Pokémon's primary type:
▪ Dragon types tend to have higher Attack stats than Ghost types, but they also have greater variance.
Which Is
better?
SLIDESMANIA.COM
Seaborn: Swarm plot
▪ Because of the limited number of observations, we could also use a swarm plot.
▪ Here, each data point is an observation, but data points are grouped together by the variable
listed on the x-axis.
SLIDESMANIA.COM
Seaborn: Overlapping plots
Both of these show similar information, so it might be useful to overlap them.
23
Interactive Visualisation
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.
➢ Hover: Hovering a cursor above an element of a plot allows the user to receive more
information about the datapoint than can be seen just by observing the plot.
➢ Zoom: Zooming in and out of a plot is a feature that quite a few interactive data
visualization libraries create on their own. They allow you to focus on specific datapoints
of a plot and take a closer look at them.
➢ Clickable parameters: There are several types of clickable parameters, such as checkboxes
and drop-down menus, that allow the user to pick and choose what aspects of the data
SLIDESMANIA.COM
25
https://buggyprogrammer.com/bokeh-vs-plotly-which-one-is-better-in-2022/
Bokeh VS Plotly VS Altair
Bokeh: Plotly: Altair:
➢ Ideal tool to build ➢ It is a JSON-based plotting tool, ➢ The basic code remains the
statistical charts quickly compatibility with R, Python, same for all types of plots, only
and easily. MATLAB, Perl, Julia, Arduino. needs to change the mark
➢ Rendered using HTML ➢ Interactive plots can easily be attribute to get different plots.
and JavaScript. shared online. ➢ The code is shorter and simpler
➢ Output from matplotlib ➢ Plotly can also be used by to write than other libraries.
and seaborn can be easily people with no technical ➢ Faceting and Interactivity are
rendered into bokeh. background by using plotly GUI. very easy to implement.
from bokeh.plotting import import plotly.express as px import altair as alt
figure, output_file, show . . . alt.Chart(data).mark_bar().encode(
SLIDESMANIA.COM
27