Introduction to relational plots and subplots IN TRODUCTION TO S - - PowerPoint PPT Presentation

introduction to relational plots and subplots
SMART_READER_LITE
LIVE PREVIEW

Introduction to relational plots and subplots IN TRODUCTION TO S - - PowerPoint PPT Presentation

Introduction to relational plots and subplots IN TRODUCTION TO S EABORN Erin Case Data Scientist Questions about quantitative variables Relational plots Height vs. weight INTRODUCTION TO SEABORN Questions about quantitative variables


slide-1
SLIDE 1

Introduction to relational plots and subplots

IN TRODUCTION TO S EABORN

Erin Case

Data Scientist

slide-2
SLIDE 2

INTRODUCTION TO SEABORN

Questions about quantitative variables

Relational plots Height vs. weight

slide-3
SLIDE 3

INTRODUCTION TO SEABORN

Questions about quantitative variables

Relational plots Height vs. weight Number of school absences vs. nal grade

slide-4
SLIDE 4

INTRODUCTION TO SEABORN

Questions about quantitative variables

Relational plots Height vs. weight Number of school absences vs. nal grade GDP vs. percent literate

slide-5
SLIDE 5

INTRODUCTION TO SEABORN

slide-6
SLIDE 6

INTRODUCTION TO SEABORN

slide-7
SLIDE 7

INTRODUCTION TO SEABORN

Introducing relplot()

Create "relational plots": scatter plots or line plots Why use relplot() instead of scatterplot() ?

relplot() lets you create subplots in a single gure

slide-8
SLIDE 8

INTRODUCTION TO SEABORN

scatterplot() vs. relplot()

Using scatterplot()

import seaborn as sns import matplotlib.pyplot as plt sns.scatterplot(x="total_bill", y="tip", data=tips) plt.show()

Using relplot()

import seaborn as sns import matplotlib.pyplot as plt sns.relplot(x="total_bill", y="tip", data=tips, kind="scatter") plt.show()

slide-9
SLIDE 9

INTRODUCTION TO SEABORN

Subplots in columns

import seaborn as sns import matplotlib.pyplot as plt sns.relplot(x="total_bill", y="tip", data=tips, kind="scatter", col="smoker") plt.show()

slide-10
SLIDE 10

INTRODUCTION TO SEABORN

Subplots in rows

import seaborn as sns import matplotlib.pyplot as plt sns.relplot(x="total_bill", y="tip", data=tips, kind="scatter", row="smoker") plt.show()

slide-11
SLIDE 11

INTRODUCTION TO SEABORN

Subplots in rows and columns

import seaborn as sns import matplotlib.pyplot as plt sns.relplot(x="total_bill", y="tip", data=tips, kind="scatter", col="smoker", row="time") plt.show()

slide-12
SLIDE 12

INTRODUCTION TO SEABORN

Subgroups for days of the week

slide-13
SLIDE 13

INTRODUCTION TO SEABORN

Wrapping columns

import seaborn as sns import matplotlib.pyplot as plt sns.relplot(x="total_bill", y="tip", data=tips, kind="scatter", col="day", col_wrap=2) plt.show()

slide-14
SLIDE 14

INTRODUCTION TO SEABORN

Ordering columns

import seaborn as sns import matplotlib.pyplot as plt sns.relplot(x="total_bill", y="tip", data=tips, kind="scatter", col="day", col_wrap=2, col_order=["Thur", "Fri", "Sat", "Sun"]) plt.show()

slide-15
SLIDE 15

Let's practice!

IN TRODUCTION TO S EABORN

slide-16
SLIDE 16

Customizing scatter plots

IN TRODUCTION TO S EABORN

Erin Case

Data Scientist

slide-17
SLIDE 17

INTRODUCTION TO SEABORN

Scatter plot overview

Show relationship between two quantitative variables We've seen: Subplots (

col and row )

Subgroups with color ( hue ) New Customizations: Subgroups with point size and style Changing point transparency Use with both scatterplot() and relplot()

slide-18
SLIDE 18

INTRODUCTION TO SEABORN

Subgroups with point size

import seaborn as sns import matplotlib.pyplot as plt sns.relplot(x="total_bill", y="tip", data=tips, kind="scatter", size="size") plt.show()

slide-19
SLIDE 19

INTRODUCTION TO SEABORN

Point size and hue

import seaborn as sns import matplotlib.pyplot as plt sns.relplot(x="total_bill", y="tip", data=tips, kind="scatter", size="size", hue="size") plt.show()

slide-20
SLIDE 20

INTRODUCTION TO SEABORN

Subgroups with point style

import seaborn as sns import matplotlib.pyplot as plt sns.relplot(x="total_bill", y="tip", data=tips, kind="scatter", hue="smoker", style="smoker") plt.show()

slide-21
SLIDE 21

INTRODUCTION TO SEABORN

Changing point transparency

import seaborn as sns import matplotlib.pyplot as plt # Set alpha to be between 0 and 1 sns.relplot(x="total_bill", y="tip", data=tips, kind="scatter", alpha=0.4) plt.show()

slide-22
SLIDE 22

Let's practice!

IN TRODUCTION TO S EABORN

slide-23
SLIDE 23

Introduction to line plots

IN TRODUCTION TO S EABORN

Erin Case

Data Scientist

slide-24
SLIDE 24

INTRODUCTION TO SEABORN

What are line plots?

Two types of relational plots: scatter plots and line plots Scatter plots Each plot point is an independent

  • bservation

Line plots Each plot point represents the same "thing", typically tracked over time

slide-25
SLIDE 25

INTRODUCTION TO SEABORN

Air pollution data

Collection stations throughout city Air samples of nitrogen dioxide levels

slide-26
SLIDE 26

INTRODUCTION TO SEABORN

Scatter plot

import matplotlib.pyplot as plt import seaborn as sns sns.relplot(x="hour", y="NO_2_mean", data=air_df_mean, kind="scatter") plt.show()

slide-27
SLIDE 27

INTRODUCTION TO SEABORN

Line plot

import matplotlib.pyplot as plt import seaborn as sns sns.relplot(x="hour", y="NO_2_mean", data=air_df_mean, kind="line") plt.show()

slide-28
SLIDE 28

INTRODUCTION TO SEABORN

Subgroups by location

slide-29
SLIDE 29

INTRODUCTION TO SEABORN

Subgroups by location

import matplotlib.pyplot as plt import seaborn as sns sns.relplot(x="hour", y="NO_2_mean", data=air_df_loc_mean, kind="line", style="location", hue="location") plt.show()

slide-30
SLIDE 30

INTRODUCTION TO SEABORN

Adding markers

import matplotlib.pyplot as plt import seaborn as sns sns.relplot(x="hour", y="NO_2_mean", data=air_df_loc_mean, kind="line", style="location", hue="location", markers=True) plt.show()

slide-31
SLIDE 31

INTRODUCTION TO SEABORN

Turning off line style

import matplotlib.pyplot as plt import seaborn as sns sns.relplot(x="hour", y="NO_2_mean", data=air_df_loc_mean, kind="line", style="location", hue="location", markers=True, dashes=False) plt.show()

slide-32
SLIDE 32

INTRODUCTION TO SEABORN

Multiple observations per x-value

slide-33
SLIDE 33

INTRODUCTION TO SEABORN

Multiple observations per x-value

Scatter plot

import matplotlib.pyplot as plt import seaborn as sns sns.relplot(x="hour", y="NO_2", data=air_df, kind="scatter") plt.show()

slide-34
SLIDE 34

INTRODUCTION TO SEABORN

Multiple observations per x-value

Line plot

import matplotlib.pyplot as plt import seaborn as sns sns.relplot(x="hour", y="NO_2", data=air_df, kind="line") plt.show()

slide-35
SLIDE 35

INTRODUCTION TO SEABORN

Multiple observations per x-value

Shaded region is the condence interval Assumes dataset is a random sample 95% condent that the mean is within this interval Indicates uncertainty in our estimate

slide-36
SLIDE 36

INTRODUCTION TO SEABORN

Replacing condence interval with standard deviation

import matplotlib.pyplot as plt import seaborn as sns sns.relplot(x="hour", y="NO_2", data=air_df, kind="line", ci="sd") plt.show()

slide-37
SLIDE 37

INTRODUCTION TO SEABORN

Turning off condence interval

import matplotlib.pyplot as plt import seaborn as sns sns.relplot(x="hour", y="NO_2", data=air_df, kind="line", ci=None) plt.show()

slide-38
SLIDE 38

Let's practice!

IN TRODUCTION TO S EABORN