How to use Seaborn in Python

7-Day Challenge

Land Your First Data Science Job

A proven roadmap to prepare for $75K+ entry-level data roles. Perfect for Data Scientist ready to level up their career.

Build portfolios that hiring managers love
Master the Python and SQL essentials to be industry-ready
Practice with real interview questions from tech companies
Access to the $100k/y Data Scientist Cheatsheet

Join thousands of developers who transformed their careers through our challenge. Unsubscribe anytime.

Why Seaborn?

Seaborn is a fantastic library to do some data visualization and it is built on top of the Matplotlib library.

Seaborn pushed the simplicity of data exploration and data analysis to the extreme.

How to import it

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
How to import Seaborn and other useful libraries

Setting the theme

sns.set_theme(style="darkgrid")
How to change the theme in Seaborn

Loading a dataset

Seaborn is made for data science, so it comes with a lot of available example datasets. At the time of this writing, the library has around 19 different datasets that you can use to practice data exploration and data visualization.

Here we import the tips dataset. This dataset contains servers' tips on a given day, the sex, etc...

One could try to predict the amount that people tip given those characteristics.

tips = sns.load_dataset("tips")

A basic plot

Let's do a basic plot that plots the total_bill and the tip that the customer left in order to see whether there is a linear relationship or not.

sns.relplot(x="total_bill", y="tip", data=tips)
Here is how to plot a scatter plot that shows the relation between two variables
Here is the result

Adding some colors

We could and it is always nice to add an extra variable as colors.

Here we have a categorical variable called smoker which tells us whether or not the customer was a smoker.

Here is the plot

sns.relplot(x="total_bill", y="tip", hue="smoker", data=tips)
Can we see an impact if the user smoke or not?

7-Day Challenge

Land Your First Data Science Job

A proven roadmap to prepare for $75K+ entry-level data roles. Perfect for Data Scientist ready to level up their career.

Build portfolios that hiring managers love
Master the Python and SQL essentials to be industry-ready
Practice with real interview questions from tech companies
Access to the $100k/y Data Scientist Cheatsheet

Join thousands of developers who transformed their careers through our challenge. Unsubscribe anytime.

Free Newsletter

Master Data Science in Days, Not Months 🚀

Skip the theoretical rabbit holes. Get practical data science skills delivered in bite-sized lessons – Approach used by real data scientist. Not bookworms. 📚

Weekly simple and practical lessons
Access to ready to use code examples
Skip the math, focus on results
Learn while drinking your coffee

By subscribing, you agree to receive our newsletter. You can unsubscribe at any time.