0% found this document useful (0 votes)
18 views

Lec8_Data_Visualization_2

This document covers the creation of basic plots using the Seaborn library in Python, including scatter plots, histograms, bar plots, box and whiskers plots, and pairwise plots. It details the necessary libraries to import, methods for customizing plots, and techniques for visualizing data relationships. The lecture builds upon previous knowledge of Matplotlib and emphasizes the aesthetic advantages of using Seaborn for statistical graphics.

Uploaded by

joydsouza054
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)
18 views

Lec8_Data_Visualization_2

This document covers the creation of basic plots using the Seaborn library in Python, including scatter plots, histograms, bar plots, box and whiskers plots, and pairwise plots. It details the necessary libraries to import, methods for customizing plots, and techniques for visualizing data relationships. The lecture builds upon previous knowledge of Matplotlib and emphasizes the aesthetic advantages of using Seaborn for statistical graphics.

Uploaded by

joydsouza054
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/ 29

Data visualization

Part II
In the previous lecture
We learnt how to create basic plots using matplotlib library

• Scatter plot

• Histogram

• Bar plot

Python for Data Science 2


In this lecture
We will learn how to create basic plots using seaborn library:
• Scatter plot
• Histogram
• Bar plot
• Box and whiskers plot
• Pairwise plots

Python for Data Science 3


Seaborn

• Seaborn is a Python data visualization library


based on matplotlib
• It provides a high-level interface for drawing
attractive and informative statistical graphics

Python for Data Science 4


Scatter plot

Python for Data Science 5


Importing libraries
 Importing necessary libraries
‘pandas’ library to work with dataframes

‘numpy’ library to do numerical operations


‘matplotlib’ library to do visualization

‘seaborn’ library to do visualization

Python for Data Science 6


Importing data into Spyder
 Importing data

 Removing missing values from the dataframe

Python for Data Science 7


Scatter plot
 Scatter plot of Price vs Age with default arguments

o By default, fit_reg = True


o It estimates and plots a regression
model relating the x and y variables

Python for Data Science 8


Scatter plot
 Scatter plot of Price vs Age without the regression fit line

Python for Data Science 9


Scatter plot
 Scatter plot of Price vs Age by customizing the appearance of markers

Python for Data Science 10


Scatter plot
 Scatter plot of Price vs Age by FuelType

 Using hue parameter, including another variable to show the fuel


types categories with different colors

Python for Data Science 11


Scatter plot
 Scatter plot of Price vs Age by FuelType

Similarly, custom the appearance of the markers


using
o transparency
o shape
o size

Python for Data Science 12


Histogram

Python for Data Science 13


Histogram
 Histogram with default kernel density estimate

Python for Data Science 14


Histogram
 Histogram without kernel density estimate

Python for Data Science 15


Histogram
 Histogram with fixed no. of bins

Python for Data Science 16


Bar plot

Python for Data Science 17


Bar plot
 Frequency distribution of fuel type of the cars

Python for Data Science 18


Grouped bar plot
 Grouped bar plot of FuelType and Automatic

Python for Data Science 19


Box and whiskers plot

Python for Data Science 20


Box and whiskers plot – numerical variable
 Box and whiskers plot of Price to visually interpret the
five-number summary

Python for Data Science 21


Box and whiskers plot
 Box and whiskers plot for numerical vs categorical variable
 Price of the cars for various fuel types

Python for Data Science 22


Grouped box and whiskers plot
 Grouped box and whiskers plot of Price vs FuelType and Automatic

Python for Data Science 23


Box-whiskers plot and Histogram
 Let’s plot box-whiskers plot and histogram on the same window
 Split the plotting window into 2 parts

Python for Data Science 24


Box-whiskers plot and Histogram
 Now, add create two plots

Python for Data Science 25


Pairwise plots
 Itis used to plot pairwise relationships in a dataset
 Creates scatterplots for joint relationships and histograms for
univariate distributions

Code:
sns.pairplot(cars_data, kind="scatter", hue="FuelType")
plt.show()

Python for Data Science 26


Pairwise plots
Output:

Python for Data Science 27


Summary
We have learnt how to create basic plots using seaborn library:
• Scatter plot
• Histogram
• Bar plot
o Grouped bar plot
• Box and whiskers plot
o Grouped box and whiskers plot
• Pairwise plots
Python for Data Science 28
THANK YOU

You might also like