0% found this document useful (0 votes)
34 views27 pages

09 Static To Interactive Visualisation

Uploaded by

nuvis.marshal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views27 pages

09 Static To Interactive Visualisation

Uploaded by

nuvis.marshal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

Static to Interactive

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.).

✓ Explanation: tells a story to an audience


(answer the questions from audience)
SLIDESMANIA.COM
Types of Data Visualisation
✓ Static: graphs and plots that are stagnant and cannot be modified in real time
✓ Interactive: can react and respond to human inputs
✓ Temporal: understand the trend of values change
✓ Geospatial: features depicting spatial or geographical aspects
SLIDESMANIA.COM
Python Data Visualization Libraries
Library Description
Because matplotlib was the first Python data visualization library, many other libraries are built on top of it or
designed to work in tandem with it during analysis. While matplotlib is good for getting a sense of the data, it’s not
Matplotlib very useful for creating publication-quality charts quickly and easily.

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

analysis tool of choice for many Python users.


Histograms
Allow you to plot the distributions of numeric variables.
SLIDESMANIA.COM
Seaborn: scatter plot
Name of variable we want Name of our dataframe
on the x-axis fed to the “data=“
command

Seaborn “linear model Name of variable we want


plot” function for on the y-axis
creating a scatter
graph
SLIDESMANIA.COM
Seaborn: scatter plot
Seaborn doesn't have a dedicated scatter plot function, use plotting a regression line; hence lmplot()
SLIDESMANIA.COM
Seaborn: Factor plots
Make it easy to separate plots by categorical classes.

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.

Set size of print canvas.

Remove bars from inside the violins

Make bars black and slightly


transparent
Give the graph a title
SLIDESMANIA.COM
Seaborn: Heatmaps
▪ Useful for visualising matrix-like data.
▪ Here, we’ll plot the correlation of the stats_df variables
SLIDESMANIA.COM
Seaborn: Bar plot
Visualises the distributions of categorical variables.

Rotates the x-ticks 45 degrees


SLIDESMANIA.COM
Seaborn: Joint Distribution Plot
Joint distribution plots combine information from scatter plots and histograms to give you detailed information
for bi-variate distributions.
SLIDESMANIA.COM
Interactive Visualisation
Interactive visualizations are often also built on dynamic data.
SLIDESMANIA.COM

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

they wish to analyze and view.


24
Interactive Visualisation
Popular Python libraries.
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

. . . fig = px.bar(x, y) encoding1 = ‘column1’,


graph.line(x, y) fig.show() encoding2 = ‘column2’,
show(graph) )
26
Practices
1. Seaborn is data visualisation library based on ______________

2. What are the libraries used for interactive visualisation?

3. When do you use interactive visualisation?


SLIDESMANIA.COM

27

You might also like