< 1/>
YZV211E
Introduction to Data Science and Engineering
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
< 2/>
Chapter 03
What is Data Visualization?
Visualization Guidelines
Chart Types
Python & Visualization
What is Data Visualization?
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
< 3/>
What is Data Visualization?
Data visualization is the graphical representation of information
and data by using visual elements like charts, graphs, and maps.
Data visualization tools provide an accessible way to see and
understand trends, outliers, and patterns in data.
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
< 4 />
Why Data Visualization is Important?
01 02 03 04
Present meaningful data Democratize your data
To see the big picture Make better decisions
Uncover insights and see patterns Understand your next steps and spend Share insights with others in an easy- Provide one source of truth for your
within complex data less time performing data analysis. to-understand form. entire organization.
Quickly act on decisions.
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Meet Anscombe’s Quartet < 5/>
All four datasets have nearly identical
descriptive statistics:
Property Value
x mean 9
x variance 11
y mean 7.5
y variance 4.125
x/y correlation 0.816
Anscombe’s Quartet comprises four data sets that have nearly
Linear regression line y = 3.00 + 0.500x
identical simple descriptive statistics
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
See Anscombe’s Quartet Visualization < 6/>
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
< 7/>
Perception vs Cognition
The main difference between cognition and perception is that cognition is the
mental process of acquiring knowledge and understanding through thought,
experience, and the senses, but perception is the ability to see, hear or become
aware of something through the senses.
Cognition and perception are two inherently tied concepts. In fact, one can say
that perception is a part of cognition. However, cognition and perception are not
the same. Cognition is a much broader concept than perception.
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
< 8/>
Bad Graphs – Bad Storytelling
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
< 9/>
Bad Graphs – Bad Storytelling
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
< 10 />
How to tell
a story?
Understand the context
Choose an appropriate visual display
Eliminate clutter
Focus attention where you want it
Think like a designer
Tell a story
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Where Do We Use Data Visualization? < 11 />
Exploratory Analysis Explanatory Analysis
Used by data analysts, statisticians, and data scientists to better Once the analysts understand the data and find their results, the
understand data. As it is rightly called, it is used to explore the best way to convey their ideas and findings is through visuals!
hidden trends, patterns in data. This is used to craft a story that will appeal to the viewer offering
deeper insights.
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
DataViz Tools
< 12
/>
matplotlib Other Tools
Matplotlib is a comprehensive library Excel, Power BI, Tableau
DataViz
for creating static, animated, and
interactive visualizations in Python Tools
seaborn Plotly Dash
Seaborn is a Python data visualization library Dash is the original low-code
based on matplotlib. It provides a high-level framework for rapidly building data
interface for drawing attractive and informative apps in Python
statistical graphics.
Bokeh
Bokeh is a Python library for creating interactive visualizations for modern web browsers. It helps you
build beautiful graphics, ranging from simple plots to complex dashboards with streaming datasets.
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
< 13 />
Chapter 03
What is Data Visualization?
Visualization Guidelines
Chart Types
Python & Visualization
Visualization Guidelines
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Gestalt Principles of
Visual Perception Closure Proximity
Clutter visual elements that take up space but
don’t increase understanding.
The Gestalt School of Psychology set out in the
early 1900s to understand how individuals Similarity Continuity
perceive order in the world around them. What
they came away with are the principles of visual
perception still accepted today that define how
people interact with and create order out of visual
stimuli.
Connection Enclosure
Proximity
< 15 />
We tend to think of objects that are physically close together as belonging to part of a group.
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Similarity
< 16 />
Objects that are of similar color, shape, size, or orientation are perceived as related or belonging to part of a group.
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Enclosure
< 17 />
We think of objects that are physically enclosed together as belonging to part of a group.
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Closure
< 18 />
The closure concept says that people like things to be simple and to fit in the constructs that are already in our heads. Because of this, people tend to
perceive a set of individual elements as a single, recognizable shape when they can—when parts of a whole are missing, our eyes fill in the gap.
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Continuity
< 19 />
When looking at objects, our eyes seek the smoothest path and naturally create continuity in what we see even where it may
not explicitly exist.
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Connection
< 20 />
We tend to think of objects that are physically connected as part of a group. The connective property typically has a stronger associative value than
similar color, size, or shape.
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Guidelines for Better Data Visualizations
< 21 />
Don’t show all the data. But that does not mean that you shouldn’t
highlight the values that are important to your argument.
Highlighting just a few countries in the chart on the right makes it
easier to read.
1. Show the data
2. Reduce the clutter
3. Integrate the graphics and text
4. Avoid the spaghetti chart
5. Start with gray
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Guidelines for Better Data Visualizations
< 22 />
The use of unnecessary visual elements distracts your reader from the
central data and clutters the page.
• Remove heavy tick marks and gridlines
• Remove data markers
• Avoid 3D graphs
• Avoid too much text, labels, cluttering space. 1. Show the data
2. Reduce the clutter
3. Integrate the graphics and text
4. Avoid the spaghetti chart
5. Start with gray
Distracting, hard to read distorting clutter A basic bar chart eliminates the clutter and the
distortion caused by the 3D effect, so the graph is
easier to read and understand.
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Guidelines for Better Data Visualizations
< 23 />
Adding the right annotations to a graph can be vitally important to
your reader’s comprehension.
• Remove legends when possible, label data directly
• Write a newspaper like headline
• Add explaining texts
1. Show the data
2. Reduce the clutter
3. Integrate the graphics and text
4. Avoid the spaghetti chart
5. Start with gray
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Guidelines for Better Data Visualizations
< 24 />
The use of unnecessary visual elements distracts your reader from the
central data and clutters the page.
• Remove legends when possible, label data directly
• Write a newspaper like headline
• Add explaining texts
1. Show the data
2. Reduce the clutter
3. Integrate the graphics and text
4. Avoid the spaghetti chart
5. Start with gray
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Guidelines for Better Data Visualizations
< 25 />
Some graphs contain too much information, line charts that look like
spaghetti, maps with dozens of colors and icons, or bar after bar after
bar littering a chart.
1. Show the data
2. Reduce the clutter
3. Integrate the graphics and text
4. Avoid the spaghetti chart
5. Start with gray
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Guidelines for Better Data Visualizations
< 26 />
Whenever you make a graph, start with allgray data elements. By
doing so, you force yourself to be purposeful and strategic in your use
of color, labels, and other elements.
1. Show the data
2. Reduce the clutter
3. Integrate the graphics and text
4. Avoid the spaghetti chart
5. Start with gray
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Secondary y-Axis
< 27
/>
Don’t Use Pie Chart
< 28
/>
< 29 />
Chapter 03
What is Data Visualization?
Visualization Guidelines
Chart Types
Python & Visualization
Chart Types
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
< 30 />
The Anatomy of a Chart
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Barchart
< 31 />
1. Whenever possible, sort the
data
2. Start the Axis at Zero
3. Don’t break the bars
4. Remove tick marks
5. Show outliers
6. Remove gridlines
7. Rotate chart if too many categories
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Source: Better Data Visualizations by J. Schwabish, 2021
Barchart
< 32 />
1. Whenever possible, sort the
data
2. Start the Axis at Zero
3. Don’t break the bars
4. Remove tick marks
5. Show outliers
6. Remove gridlines
7. Rotate chart if too many categories
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Source: Better Data Visualizations by J. Schwabish, 2021
Barchart
< 33 />
1. Whenever possible, sort the
data
2. Start the Axis at Zero
3. Don’t break the bars
4. Remove tick marks
5. Show outliers
6. Remove gridlines
7. Rotate chart if too many categories
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Source: Better Data Visualizations by J. Schwabish, 2021
Barchart
< 34 />
1. Whenever possible, sort the
data
2. Start the Axis at Zero
3. Don’t break the bars
4. Remove tick marks
5. Show outliers
6. Remove gridlines
7. Rotate chart if too many categories
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Source: Better Data Visualizations by J. Schwabish, 2021
Barchart
< 35 />
1. Whenever possible, sort the
data
2. Start the Axis at Zero
3. Don’t break the bars
4. Remove tick marks
5. Show outliers
6. Remove gridlines
7. Rotate chart if too many categories
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Source: Better Data Visualizations by J. Schwabish, 2021
Barchart
< 36 />
1. Whenever possible, sort the
data
2. Start the Axis at Zero
3. Don’t break the bars
4. Remove tick marks
5. Show outliers
6. Remove gridlines
7. Rotate chart if too many categories
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Source: Better Data Visualizations by J. Schwabish, 2021
Barchart
< 37 />
1. Whenever possible, sort the
data
2. Start the Axis at Zero
3. Don’t break the bars
4. Remove tick marks
5. Show outliers
6. Remove gridlines
7. Rotate chart if too many categories
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Source: Better Data Visualizations by J. Schwabish, 2021
Paired Barchart
< 38 />
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Source: Better Data Visualizations by J. Schwabish, 2021
Stacked Barchart
< 39 />
While the paired bar chart
shows two or more data values
for each category, this chart
subdivides the data within
each category.
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Source: Better Data Visualizations by J. Schwabish, 2021
Dot Plot
< 40 />
While the paired bar chart
shows two or more data values
for each category, this chart
subdivides the data within
each category.
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Source: Better Data Visualizations by J. Schwabish, 2021
Heatmaps
< 41 />
Heatmaps use colors and color
saturations to represent data
values. A heatmap is a table
with color-coded cells. They
are often used to visualize
high-frequency data or when
seeing general patterns is
more important than exact
values.
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Sankey Diagrams
< 42 />
Sankey diagrams are useful for
showing how categories
compare to one another and
flow into other states or
categories.
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Source: Better Data Visualizations by J. Schwabish, 2021
Waterfall Charts
< 43 />
A waterfall chart shows a
running total as values are
added or subtracted.
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Source: Better Data Visualizations by J. Schwabish, 2021
Line Charts
< 44 />
A waterfall chart shows a
running total as values are
added or subtracted.
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Source: Better Data Visualizations by J. Schwabish, 2021
Slope Charts
< 45 />
When there are 2 categories in
a paired bar chart, slope charts
are a good alternative.
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Source: Better Data Visualizations by J. Schwabish, 2021
Area Charts
< 46 />
Area charts are like line
graphs with the area below the
line filled.
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Source: Better Data Visualizations by J. Schwabish, 2021
Stacked Area Charts
< 47 />
Stacked area charts are area
charts showing multiple series
stacked over each other sum
to a total value.
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Source: Better Data Visualizations by J. Schwabish, 2021
Stacked Area Charts
< 48 />
Stacked area charts are area
charts showing multiple series
stacked over each other sum
to a total value.
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Source: Better Data Visualizations by J. Schwabish, 2021
Stacked Area Charts
< 49 />
Stacked area charts are also a
good choice when we want to
show the change of the
distribution of a data series.
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Source: Better Data Visualizations by J. Schwabish, 2021
Confidence Interval Chart
< 50 />
In a confidence interval chart,
we generally use lines or
colored areas to show the
ranges of uncertainty.
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Source: Better Data Visualizations by J. Schwabish, 2021
Confidence Interval Chart
< 51 />
In a confidence interval chart,
we generally use lines or
colored areas to show the
ranges of uncertainty.
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Source: Better Data Visualizations by J. Schwabish, 2021
Scatter Plot
< 52 />
A scatter plot is a type of plot
using Cartesian coordinates to
display values for typically two
variables for a set of data.
Unlike a bar chart, the scatterplot
axes do not necessarily need to
start at zero, especially if zero is
not a possible value for the data
series.
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Scatter Plot
< 53 />
Scatter plots are usually
preferred when we want to
illustrate the correlations (or
lack of correlations) between
two variables.
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Scatter Plot
< 54 />
Scatter plots are usually
preferred when we want to
illustrate the correlations (or
lack of correlations) between
two variables.
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Source: Better Data Visualizations by J. Schwabish, 2021
Bubble Plot
< 55 />
By changing the sizes of circles
in a scatter plot according to a
third value, a scatter plot can
be converted to a bubble plot.
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Source: Better Data Visualizations by J. Schwabish, 2021
Bubble Plot
< 56 />
By changing the sizes of circles
in a scatter plot according to a
third value, a scatter plot can
be converted to a bubble plot.
We can vary the color of circles
to denote another variable.
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Source: Better Data Visualizations by J. Schwabish, 2021
Box-and-Whisker Graph
< 57 />
Maximum
Upper Quartile (Q2)
This plot type is used when we
want to show the specific
Interquartile Range percentile values within a
(IQR)
distribution.
Median
Lower Quartile (Q1)
Minimum
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Box-and-Whisker Graph
< 58 />
This plot type is used when we
want to show the specific
percentile values within a
distribution.
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Source: Better Data Visualizations by J. Schwabish, 2021
Candlestick Plot
< 59 />
Maximum Maximum
Close Open
Although it looks similar to
box-and-whisker plots,
candlestick plots visualize
different content. Candlestick
plots are especially used in
finance to denote the opening,
Open Close
closing, maximum and
minimum prices at a time
period.
Minimum Minimum
Increasing Decreasing
(Bullish) (Bearish)
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Candlestick Chart
< 60 />
Although it looks similar to
box-and-whisker plots,
candlestick plots visualize
different content. Candlestick
plots are especially used in
finance to denote the opening,
closing, maximum and
minimum prices at a time
period.
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Radar (Spider) Chart
< 61 />
A radar chart is a graphical
method of displaying
multivariate data in the form
of a two-dimensional chart of
three or more quantitative
variables represented on axes
starting from the same point.
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Network Diagrams
< 62 />
Network diagrams are used to
show hierarchies among
different groups.
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Treemaps
< 63 />
Treemapping is a method for
displaying hierarchical data
using nested figures, usually
rectangles.
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Source: Better Data Visualizations by J. Schwabish, 2021
Word Clouds
< 64 />
In a word cloud, the size of
each word is adjusted
according to its frequency in a
passage.
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Source: Better Data Visualizations by J. Schwabish, 2021
Geospatial Charts
< 65 />
In geospatial plots, we
may add color areas
(like states or cities),
add circles or lines on
top of a geographical
map.
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Tables
< 66 />
When we want to show the every data you have, properly designed tables
may help you. Still, it is not very useful when you have a lot of data.
Like charts, tables can also
suffer from clutter and poor-
design. There are some
guidelines to properly prepare
a data table.
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Source: Better Data Visualizations by J. Schwabish, 2021
Data Table Guidelines
< 67 />
Make your column titles clear. You may use boldfacing or use separating
lines.
1. Offset the headers from the body
2. Avoid heavy gridlines
3. Right align numbers and headers
4. Left align text and headers
5. Use appropriate level of precision
6. Adjust spacing between rows&columns
7. Remove unit repetition
8. Highlight outliers
9. Group similar data
10. Add visuals when appropriate
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Source: Better Data Visualizations by J. Schwabish, 2021
Data Table Guidelines
< 68 />
You should lighten (even may remove) the borders and other dividers to
reduce clutter.
1. Offset the headers from the body
2. Avoid heavy gridlines
3. Right align numbers and headers
4. Left align text and headers
5. Use appropriate level of precision
6. Adjust spacing between rows&columns
7. Remove unit repetition
8. Highlight outliers
9. Group similar data
10. Add visuals when appropriate
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Source: Better Data Visualizations by J. Schwabish, 2021
Data Table Guidelines
< 69 />
Right-align numbers and their headers. You may add extra digits to
maintain uniformity. Also use a proper font which uses the same baseline
for digits.
1. Offset the headers from the body
2. Avoid heavy gridlines
3. Right align numbers and headers
4. Left align text and headers
5. Use appropriate level of precision
6. Adjust spacing between rows&columns
7. Remove unit repetition
8. Highlight outliers
9. Group similar data
10. Add visuals when appropriate
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Source: Better Data Visualizations by J. Schwabish, 2021
Data Table Guidelines
< 70 />
1. Offset the headers from the body
2. Avoid heavy gridlines
3. Right align numbers and headers
4. Left align text and headers
5. Use appropriate level of precision
6. Adjust spacing between rows&columns
7. Remove unit repetition
8. Highlight outliers
9. Group similar data
10. Add visuals when appropriate
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Source: Better Data Visualizations by J. Schwabish, 2021
Data Table Guidelines
< 71 />
1. Offset the headers from the body
2. Avoid heavy gridlines
3. Right align numbers and headers
4. Left align text and headers
5. Use appropriate level of precision
6. Adjust spacing between rows&columns
7. Remove unit repetition
8. Highlight outliers
9. Group similar data
10. Add visuals when appropriate
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Source: Better Data Visualizations by J. Schwabish, 2021
Data Table Guidelines
< 72 />
You may guide the reader by adjusting the spaces between rows and
columns.
1. Offset the headers from the body
2. Avoid heavy gridlines
3. Right align numbers and headers
4. Left align text and headers
5. Use appropriate level of precision
6. Adjust spacing between rows&columns
7. Remove unit repetition
8. Highlight outliers
9. Group similar data
10. Add visuals when appropriate
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Source: Better Data Visualizations by J. Schwabish, 2021
Data Table Guidelines
< 73 />
Try to use the title or column header area to denote units, do not repeat
units in every row. Another option may be using units in the first row only.
1. Offset the headers from the body
2. Avoid heavy gridlines
3. Right align numbers and headers
4. Left align text and headers
5. Use appropriate level of precision
6. Adjust spacing between rows&columns
7. Remove unit repetition
8. Highlight outliers
9. Group similar data
10. Add visuals when appropriate
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Source: Better Data Visualizations by J. Schwabish, 2021
Data Table Guidelines
< 74 />
You may highlight the important data points (best scores or outliers).
1. Offset the headers from the body
2. Avoid heavy gridlines
3. Right align numbers and headers
4. Left align text and headers
5. Use appropriate level of precision
6. Adjust spacing between rows&columns
7. Remove unit repetition
8. Highlight outliers
9. Group similar data
10. Add visuals when appropriate
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Source: Better Data Visualizations by J. Schwabish, 2021
Data Table Guidelines
< 75 />
Avoid repetition by grouping similar data.
1. Offset the headers from the body
2. Avoid heavy gridlines
3. Right align numbers and headers
4. Left align text and headers
5. Use appropriate level of precision
6. Adjust spacing between rows&columns
7. Remove unit repetition
8. Highlight outliers
9. Group similar data
10. Add visuals when appropriate
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Source: Better Data Visualizations by J. Schwabish, 2021
Data Table Guidelines
< 76 />
Using small line or bar charts can dramatically improve the visual
perception in a table.
1. Offset the headers from the body
2. Avoid heavy gridlines
3. Right align numbers and headers
4. Left align text and headers
5. Use appropriate level of precision
6. Adjust spacing between rows&columns
7. Remove unit repetition
8. Highlight outliers
9. Group similar data
10. Add visuals when appropriate
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Source: Better Data Visualizations by J. Schwabish, 2021
Data Table Guidelines
< 77 />
1. Offset the headers from the body
2. Avoid heavy gridlines
3. Right align numbers and headers
4. Left align text and headers
5. Use appropriate level of precision
6. Adjust spacing between rows&columns
7. Remove unit repetition
8. Highlight outliers
9. Group similar data
10. Add visuals when appropriate
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Source: Better Data Visualizations by J. Schwabish, 2021
< 78 />
Chapter 03
What is Data Visualization?
Visualization Guidelines
Chart Types
Python & Visualization
Python & Visualization
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
< 79 />
matplotlib
Matplotlib is a comprehensive library for creating static, animated, and interactive visualizations in Python. It
provides an object-oriented API for embedding plots into applications using general-purpose GUI toolkits like
Tkinter, wxPython, Qt, or GTK.
The plotting capabilities in pandas and seaborn are powered by matplotlib. These packages provide wrappers
around the lower-level functionality in matplotlib.
We may find that the pandas or seaborn implementation isn't quite meeting our needs, and, indeed, it may be
impossible to override a particular setting after creating the plot with them, meaning we will have to do some of
the legwork with matplotlib.
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
< 80 />
The Anatomy of a
matplotlib figure
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Simple Example
< 81 />
%matplotlib inline
import [Link] as plt
import pandas as pd
fb = pd.read_csv('fb_stock_prices_2018.csv’,
index_col='date’,
parse_dates=True)
[Link]([Link], [Link])
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Stacked Bar Chart Example
< 82 />
import [Link] as plt
labels = ['G1', 'G2', 'G3', 'G4', 'G5']
men_means = [20, 35, 30, 35, 27]
women_means = [25, 32, 34, 20, 25]
men_std = [2, 3, 4, 1, 2]
women_std = [3, 5, 2, 3, 3]
width = 0.35
fig, ax = [Link]()
[Link](labels, men_means, width, yerr=men_std, label='Men')
[Link](labels, women_means, width, yerr=women_std,
bottom=men_means, label='Women')
ax.set_ylabel('Scores')
ax.set_title('Scores by group and gender')
[Link]()
[Link]()
[Link]
glr-gallery-lines-bars-and-markers-bar-stacked-py
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Stacked Area Chart
< 83 />
import numpy as np
import [Link] as plt
# data from United Nations World Population Prospects
# [Link] license: CC BY 3.0 IGO
year = [1950, 1960, 1970, 1980, 1990, 2000, 2010, 2018]
population_by_continent = {
'africa': [228, 284, 365, 477, 631, 814, 1044, 1275],
'americas': [340, 425, 519, 619, 727, 840, 943, 1006],
'asia': [1394, 1686, 2120, 2625, 3202, 3714, 4169, 4560],
'europe': [220, 253, 276, 295, 310, 303, 294, 293],
'oceania': [12, 15, 19, 22, 26, 31, 36, 39],
}
fig, ax = [Link]()
[Link](year, population_by_continent.values(),
labels=population_by_continent.keys())
[Link](loc='upper left')
ax.set_title('World population')
ax.set_xlabel('Year')
ax.set_ylabel('Number of people (millions)')
[Link]()
[Link]
hx-glr-gallery-lines-bars-and-markers-stackplot-demo-py
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Matplotlib < 84 />
Cheatsheets
[Link]
cheatsheets#cheatsheets
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Matplotlib < 85 />
Cheatsheets
[Link]
cheatsheets#cheatsheets
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Matplotlib < 86 />
Handouts
[Link]
cheatsheets#cheatsheets
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Matplotlib < 87 />
Handouts
[Link]
cheatsheets#cheatsheets
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
Matplotlib < 88 />
Handouts
[Link]
cheatsheets#cheatsheets
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ
< 89 />
End of chapter
Please study yourself on what you have learned today!
YZV211E Introduction to Data Science and Engineering by A. Cüneyd TANTUĞ