Seaborn
Source: 10-Data Analysis With Python/10.6-seaborn.ipynb
Start here — no coding background needed
What you will learn
Prettier statistical charts built on matplotlib.
In simple words
Seaborn makes beautiful plots with less code — use after pandas basics.
Spreadsheet-style work with code — for data jobs. Beginners: read concepts, run small examples.
Easy example — run this first. Change values and press Run again.
Runs in your browser via Pyodide — no server. First run may take a few seconds.
Reference notes (from full bootcamp)
Optional — deeper detail for when you are ready
Data Visualization With Seaborn
Seaborn is a Python visualization library based on Matplotlib that provides a high-level interface for drawing attractive and informative statistical graphics. Seaborn helps in creating complex visualizations with just a few lines of code. In this lesson, we will cover the basics of Seaborn, including creating various types of plots and customizing them.
!pip install seaborn
Browser practice only — full example needs Python on your computer (files, Flask, threads, etc.).
Runs in your browser via Pyodide — no server. First run may take a few seconds.
Expected (from notebook):
total_bill tip sex smoker day time size
0 16.99 1.01 Female No Sun Dinner 2
1 10.34 1.66 Male No Sun Dinner 3
2 21.01 3.50 Male No Sun Dinner 3
3 23.68 3.31 Male No Sun Dinner 2
4 24.59 3.61 Female No Sun Dinner 4
.. ... ... ... ... ... ... ...
239 29.03 5.92 Male No Sat Dinner 3
240 27.18 2.00 Female Yes Sat Dinner 2
241 22.67 2.00 Male Yes Sat Dinner 2
242 17.82 1.75 Male No Sat Dinner 2
243 18.78 3.00 Female No Thur Dinner 2
[244 rows x 7 columns]Runs in your browser via Pyodide — no server. First run may take a few seconds.
##create a scatter plot
import matplotlib.pyplot as plt
sns.scatterplot(x='total_bill',y='tip',data=tips)
plt.title("Scatter Plot of Total Bill vs Tip")
plt.show()Browser practice only — full example needs Python on your computer (files, Flask, threads, etc.).
## Line Plot
sns.lineplot(x='size',y='total_bill',data=tips)
plt.title("Line Plot of Total bill by size")
plt.show()Browser practice only — full example needs Python on your computer (files, Flask, threads, etc.).
## Categorical Plots
## BAr Plot
sns.barplot(x='day',y='total_bill',data=tips)
plt.title('Bar Plot of Total Bill By Day')
plt.show()Browser practice only — full example needs Python on your computer (files, Flask, threads, etc.).
Expected (from notebook): <Axes: xlabel='day', ylabel='total_bill'>
Runs in your browser via Pyodide — no server. First run may take a few seconds.
Expected (from notebook): <Axes: xlabel='day', ylabel='total_bill'>
Runs in your browser via Pyodide — no server. First run may take a few seconds.
Expected (from notebook): <Axes: xlabel='total_bill', ylabel='Count'>
Runs in your browser via Pyodide — no server. First run may take a few seconds.
Expected (from notebook): <Axes: xlabel='total_bill', ylabel='Density'>
Runs in your browser via Pyodide — no server. First run may take a few seconds.
Expected (from notebook): <seaborn.axisgrid.PairGrid at 0x27547277770>
Runs in your browser via Pyodide — no server. First run may take a few seconds.
Expected (from notebook):
total_bill tip sex smoker day time size
0 16.99 1.01 Female No Sun Dinner 2
1 10.34 1.66 Male No Sun Dinner 3
2 21.01 3.50 Male No Sun Dinner 3
3 23.68 3.31 Male No Sun Dinner 2
4 24.59 3.61 Female No Sun Dinner 4
.. ... ... ... ... ... ... ...
239 29.03 5.92 Male No Sat Dinner 3
240 27.18 2.00 Female Yes Sat Dinner 2
241 22.67 2.00 Male Yes Sat Dinner 2
242 17.82 1.75 Male No Sat Dinner 2
243 18.78 3.00 Female No Thur Dinner 2
[244 rows x 7 columns]Runs in your browser via Pyodide — no server. First run may take a few seconds.
Expected (from notebook):
total_bill tip size
total_bill 1.000000 0.675734 0.598315
tip 0.675734 1.000000 0.489299
size 0.598315 0.489299 1.000000Runs in your browser via Pyodide — no server. First run may take a few seconds.
Expected (from notebook): <Axes: >
Runs in your browser via Pyodide — no server. First run may take a few seconds.
import pandas as pd
sales_df=pd.read_csv('sales_data.csv')
sales_df.head()Browser practice only — full example needs Python on your computer (files, Flask, threads, etc.).
## Plot total sales by product
plt.figure(figsize=(10,6))
sns.barplot(x='Product Category',y="Total Revenue",data=sales_df,estimator=sum)
plt.title('Total Sales by Product')
plt.xlabel('Product')
plt.ylabel('Total Sales')
plt.show()Browser practice only — full example needs Python on your computer (files, Flask, threads, etc.).
## Plot total sales by Region
plt.figure(figsize=(10,6))
sns.barplot(x='Region',y="Total Revenue",data=sales_df,estimator=sum)
plt.title('Total Sales by Region')
plt.xlabel('Region')
plt.ylabel('Total Sales')
plt.show()Browser practice only — full example needs Python on your computer (files, Flask, threads, etc.).
Practice test — try yourself
Write code, press Check. Wrong answer shows the correct code to copy & run.
You learned "Seaborn". Use print() to show: Done: Seaborn
Hint: Use one print() with the exact text.