[go: up one dir, main page]

0% found this document useful (0 votes)
113 views39 pages

Data Visualization: Created By: Joshua Rafael Sanchez

The document discusses various Python libraries for data visualization, including Matplotlib and Seaborn for basic static visuals, Plotly for more interactive visuals, and Tableau for no-code visualization. It provides an overview of each tool's functionality and compares their advantages and disadvantages. The document is intended to help users choose the appropriate visualization library based on their specific data and presentation needs.

Uploaded by

NicholasRahe
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)
113 views39 pages

Data Visualization: Created By: Joshua Rafael Sanchez

The document discusses various Python libraries for data visualization, including Matplotlib and Seaborn for basic static visuals, Plotly for more interactive visuals, and Tableau for no-code visualization. It provides an overview of each tool's functionality and compares their advantages and disadvantages. The document is intended to help users choose the appropriate visualization library based on their specific data and presentation needs.

Uploaded by

NicholasRahe
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/ 39

Data Visualization

Created By:
Joshua Rafael Sanchez
joshuarafael@berkeley.edu
Part 1
Module Basic Visuals | Matplotlib, Seaborn
Basic Visualization Concepts, Introduction and
Comparison b/t Matplotlib and Seaborn Python Libraries
Structure in Jupyter Notebook.

● Notebooks
● Slideshow
● Homework
● References Part 2
Interactive Visuals | Plotly, Bokeh, Tableau, etc.
Deeper insights into more interactive and fun data
visualization functions. Introduction to Plotly, Bokeh and
Tableau.

Icons made by Freepik from www.flaticon.com.


Table of Contents
(Note: Click on hyperlinks to go to different parts of the slides.)

0. About/Intro 2. Seaborn 3. Plotly 4. Tableau 5. References


● About Seaborn ● About Plotly ● About Tableau ● Links to Notebooks
1. Matplotlib ● Installing Seaborn ● Installing Plotly ● Tableau Desktop ● References Cited
● About Matplotlib ● Theme Adjustments (w/ ● Using Plotly Offline or ● No-Code
● Installing Matplotlib ex) Online Visualization Tools
● Object Hierarchy ● Plotly Examples ● Visualization
● Functional/MATLAB ● Plotly Alternatives: Comparison
Approach (w/ ex) ○ Bokeh (w/ ex)
● Object-Oriented ○ D3.js
Approach (w/ ex)
What is data visualization?
Data visualization is the graphical representation of
Data information and data.

Visualization
What makes for effective data visualization?
Visualization transforms data into images effectively
Data-X: Applied Data
and accurately represent information about the data.
Ventures
Sutardja Center at UC Berkeley

What are the advantages of data visualization?


Makes for easier interpretation of patterns and trends
as opposed to looking at data in a tabular/spreadsheet
format.
Examples of Data Visualizations
Left to Right: John Snow’s 1854 Cholera Outbreak Map, Demographic Gender Breakdown,
Government Budget Treemap of Benin
About Data Visualization
Painting a Picture of Data Visualization:
● Oxford English Dictionary Definition, 1989: To form a mental image, picture of (something
not present or visible to the sight, or of an abstraction); to make visible to the mind or
imagination
● There are 3 goals: To explore data, to analyze data, and/or to present data.

Question: What Would You Like to Show?


● Relationships between variables
● Composition of the data over time
● Distribution of variable(s) in data
● Comparison of data with relation to time, variables, categories, etc.
About Data Visualization
Matplotlib
matplotlib.org/gallery
Matplotlib - About
About Matplotlib:
● Matplotlib is a comprehensive library for creating static, animated and interactive
visualizations in Python.
● Usage: Matplotlib/Pandas is mostly used for quick plotting of Pandas DataFrames and time
series analysis.

Pros and Cons of Matplotlib:


● Pro: Easy to setup and use.
● Pro: Very customizable.
● Con: Visual presentation tends to be simple compared to other tools.

Matplotlib Seaborn Plotly Tableau Resources


Matplotlib - Installation
Installing Matplotlib should be straightforward. Sample code for installing packages:

Matplotlib Seaborn Plotly Tableau Resources


Matplotlib - Object Hierarchy

● Figure: Outermost container for a


Matplotlib graphic. Can contain
multiple Axes objects.
● Axes: Actual plots. Contain smaller
objects (tick marks, individual lines,
etc.)
● Artist: Everything that is seen on
the figure is an artist.

Matplotlib Seaborn Plotly Tableau Resources


Matplotlib - 2 Approaches to Plotting
1. Functional/MATLAB Approach (Non-Pythonic)
● Most common way of Matplotlib.
● Pro: Easy approach for interactive use.
● Con- Not pythonic: Relies on global functions (where variables are declared outside of
functions) and displays global figures.

2. Object-Oriented Approach (Pythonic)


● Recommended way to use Matplotlib.
● Pro: Pythonic is object-oriented (you can build plots explicitly using methods of
the figure and the classes it contains.

Matplotlib Seaborn Plotly Tableau Resources


Matplotlib - Non-Pythonic Example
Example: Combining Line & Scatter Plots From Categorical Variables

Matplotlib Seaborn Plotly Tableau Resources


Matplotlib - Pythonic Example
Example: Simple Line Plot & Bar Plot

Matplotlib Seaborn Plotly Tableau Resources


Seaborn
seaborn.pydata.org
Seaborn - About
About Seaborn:
● Seaborn is a Python data visualization library based on Matplotlib. It provides a high-level
interface for drawing attractive and informative statistical graphics.
● Usage: Those who want to create amplified data visuals, especially in color.

Seaborn’s Pros and Cons:


● Pro: Includes higher level interfaces and settings than does Matplotlib
● Pro: Relatively simple to use, just like Matplotlib.
● Pro: Easier to use when working with Dataframes.
● Con: Like Matplotlib, data visualization seems to be simpler than other tools.

Matplotlib Seaborn Plotly Tableau Resources


Seaborn - Installation
Installing Seaborn should also be straightforward. Sample code:

Matplotlib Seaborn Plotly Tableau Resources


Seaborn - Theme Adjustments
Theme Design- Setting Style:
● Use the five built-in themes to style the figure/background of plots:
○ Grids: darkgrid, whitegrid
○ Colors: dark, white, ticks.

Setting Scale:
● Use the four scaling plot presets to customize the size of the plot:
○ In order of relative size: paper, notebook, talk, poster.

Setting Fonts and Line Widths:


● How to change the size of the text:
○ Change the font_scale parameter for sns.set_context().
● How to change the line width of the text:
○ Change the rc parameter for sns.set_context().

Matplotlib Seaborn Plotly Tableau Resources


Seaborn - Theme Adjustments w/ Examples
Let’s look at the 5 built-in themes to style the figure (background of plots):
● Grids: darkgrid, whitegrid
● Colors: dark, white, and ticks.
Consider examples using famous Iris Flower Data Set. Features of graphs:
● Left graph uses vertical bar plot w/ whitegrid, right graph uses swarm plot with dark.

Matplotlib Seaborn Plotly Tableau Resources


Seaborn - Theme Adjustments: Color
Option 1- Default & Built-In Color
Palettes:
● About: Seaborn has six variations of its
default color palette: deep, muted,
pastel, bright, dark and colorblind.
● How to use: Use
sns.color_palette() or
sns.set_palette() for individual
plots.
○ To set a color palette for all plots,
use sns.set(*args).

Matplotlib Seaborn Plotly Tableau Resources


Seaborn - Theme Adjustments: Color
Option 2- Color Brewer Palettes:
● About: Created from the research of
cartographer Cindy Brewer, these
color palettes are specifically chosen
as to be easy to interpret ordered
categories.
● How to use: Use
sns.color_palette() or
sns.set_palette() for individual
plots.
○ To set a color palette for all
plots, use sns.set(*args).

Matplotlib Seaborn Plotly Tableau Resources


Seaborn - Theme Adjustments: Color Examples
Left image: Code and resulting plot using default & built-in color palettes.
Right image: Code and resulting plot using a Color Brewer palette.

Matplotlib Seaborn Plotly Tableau Resources


Matplotlib vs. Seaborn

● Visuals
● Options
● Interactivity

Matplotlib Seaborn Plotly Tableau Resources


Plotly
plotly.com/python
Plotly - About
About Plotly:
● From website: Plotly is an interactive, open-source plotting library that supports over 40
unique chart types.
● Usage: Plotly is advantageous for those who want an interactive environment which many
use cases, ranging from statistics to finance to geography and more.

Pros and Cons of Plotly:


● Pro: Make beautiful, interactive, exportable figures in just a few lines of code.
● Pro: Much more interactive & visually flexible than Matplotlib or Seaborn.
● Con: Confusing initial setup to use Plotly without an online account, and lots of
code to write.
● Con: Out-of-date documentation and the large range of Plotly tools (Chart
Studio, Express, etc.) make it hard to keep up.

Matplotlib Seaborn Plotly Tableau Resources


Plotly - Installing
Installing Plotly Offline: (if you want to host locally on your own computer)
● Steps: You need to import packages and use commands:
○ Resource: Keep checking current version: Initialization for Online Plotting
○ Command to create standalone HTML: plotly.offline.plot()
○ Command to create plot in Jupyter Notebook: plotly.offline.iplot()

Installing Plotly Online: (use if you want to host graphs in plotly account)
● How to: You must create an account to run:
1. Set up an account at plot.ly
2. Get a User ID and API keys
3. Sign keys into the account.

Matplotlib Seaborn Plotly Tableau Resources


Plotly - Alternatives (Bokeh, D3.js)
Bokeh:
● Bokeh is an interactive visualization Python library.
● Provides elegant and concise construction of versatile graphics.
● Usage: Can be used in Jupyter Notebooks and can provide high-performance interactive
charts and plots.

D3.js:
● D3.js (used with Flask) is a framework used with HTML, CSS, and Javascript together to
create visualizations.
● Usage: Use D3.js build-in data-driven transitions for extra customization and elevated
visualization for your data.
● Pro: Helps build type of framework you want (Plotly uses D3.js library, here you can use the
D3.js library itself; open-source)
● Con: High learning curve; you need to learn HTML, CSS, Javascript

Matplotlib Seaborn Plotly Tableau Resources


Bokeh - Example
Example of using Bokeh from article. Screenshots of interactive features that Bokeh offers:

Matplotlib Seaborn Plotly Tableau Resources


Tableau
https://www.tableau.com/
Tableau: Intro & Setup
What Are Dashboards:
● Dashboards act as a data visualization tool where users can easily analyze trends and
statistics. It can be a powerful way of communicating results of a Data Science project.
● Examples: Dash by Plotly, Bokeh Dashboards, Google Data Studio, Tableau

About Tableau (Tableau Desktop):


● Pros: Makes the charts and interface almost seamlessly.
● Con: Getting used to the interface and functions.
● Con: Data cleaning/pre-processing easier in Python.

Setting up:
● 1-year free trial of Tableau Desktop for Students. (Paid differs by individual vs organization.)
● Tableau Public (create separate account); share data visualizations with global community.
● Introductory videos are a great resource; robust and go through examples in detail.

Matplotlib Seaborn Plotly Tableau Resources


Tableau - Tableau Desktop (for Students)
Go to this link to try out a trial: https://www.tableau.com/academic/students

Matplotlib Seaborn Plotly Tableau Resources


Tableau - Tableau Desktop (for Students)
When you download the Tableau Desktop Application (MacBook Pro):

Matplotlib Seaborn Plotly Tableau Resources


Explore: No-Code Visualization Tools
Infogram: | https://infogram.com/app/
● Web-based visualization environment; infographic environment.
● Multiple PDF/PNG or HTML-based templates; interactivity built-in.
● Paid version offers: Engagement analytics, team collaboration, consistent product branding.

Flourish: | https://flourish.studio/examples/
● Another web-based visualization environment.
● Interest: Interface is pretty straightforward, and visualizations can be really interactive.
● Note: Best for spreadsheet junkies!

Datawrapper: | https://www.datawrapper.de/
● Web-based visualization and map creation environment.
● Niche service, offers some powerful capabilities.
● Fact: Interesting workflow.

Matplotlib Seaborn Plotly Tableau Resources


Visualization Tools Comparison
Data import & Viz options & Free/paid More or less
usage customization features technical?

- Can import from many - Many graph options. - Tableau Public - More technical due to
data types. - Experienced users - Tableau Desktop interface and multitude
- Robust manipulation. understand benefit. (1-Year free trial student) of options.

- Can import from some - Many infographic - Free w/ account; - Less technical
data types. visual options. - Make publicly available - No code; interface
- Some manipulation. - Drag & drop interface. PDF, PNG or HTML accessible to all.

- Import from Microsoft - Graph, infographic - Free w/ account; - Less technical


Excel, CSV, JSON. and slide options. - Embed, PDF, PNG, or - No code; interface
- Some manipulation. - Straightforward editing HTML. accessible to all.
interface.

- Import from multiple - Static graph options. - Free (no account need) - Less technical.
sources. - Streamlined process - PDF, PNG, or HTML - Frequently used by
- Minimal manipulation. of creating visualizations journalists/newspapers.

Matplotlib Seaborn Plotly Tableau Resources


References
Data Visualization - References
Color Palette & Logos

Berkeley Blue California Gold Black Dark Gray Light Gray


#003262 #FDB515 #000000 #434343 #efefefff

Font: Helvetica Neue


Size of Titles: 28
Diagram Styleguide
Ticker Template (Copy and Paste)

Ticker Ticker Ticker Ticker Ticker


Example Title
“Replace Header 1 Header 1
squares with Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet,
icons” consectetur adipiscing elit. consectetur adipiscing elit.
Proin vitae tincidunt dolor. Proin vitae tincidunt dolor.

Header 1 Header 1
Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet,
consectetur adipiscing elit. consectetur adipiscing elit.
Proin vitae tincidunt dolor. Proin vitae tincidunt dolor.

Header 1 Header 1
Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet,
consectetur adipiscing elit. consectetur adipiscing elit.
Proin vitae tincidunt dolor. Proin vitae tincidunt dolor.

Ticker Ticker Ticker Ticker Ticker

You might also like