๐จ๐ฏ Professor Bheem & Patlu Panditโs Seaborn Safari!
๐ Chapter 1 โ Introduction to Seaborn
(Scene: In the colorful kingdom of โData Nagarโ, Professor Bheem is peacefully drinking lassi under a banyan tree. Patlu Pandit rushes in, tripping over a stack of CSV files.)
Patlu: โBheem! My graphs look uglier than my 5th standard photo!โ
Professor Bheem: โBeta Patluโฆ even your Aadhaar photo has better clarity than your plots.โ
Patlu: โBas! Teach me magic!โ
Bheem: โThen comeโฆ today we learn Seaborn, the painter of beautiful data!โ
๐จ What is Seaborn?
Bheemโs Wisdom:
โMatplotlib is like a chalkboard. Seaborn is like a full Bollywood movie setโcolorful, dramatic, automatically stylish.โ
๐ถ Simple Definition
Seaborn is a Python library that makes beautiful, statistical visualizations easily.
It sits on top of Matplotlib and improves:
โ Colors
โ Layout
โ Clean style
โ Complex plots made simple
๐ญ Seaborn vs. Matplotlib โ The Desi Analogy
Matplotlib = Plain idli
Seaborn = Masala idli with chutney, sambhar, and garnishing
Plotly = 5-star buffet with unlimited gulab jamuns
Patlu: โCan I eat the data also?โ
Bheem: โBeta, only your brain needs feeding.โ
๐ ๏ธ Installing Seaborn
pip install seaborn
๐ Importing Seaborn
import seaborn as sns
import matplotlib.pyplot as plt
๐ First Taste of Seaborn
import seaborn as sns
sns.set_theme()
Output Meaning:
You activated โBheem modeโ โ clean backgrounds, better fonts, smoother colors.
๐งญ When Should You Use Seaborn?
Use Seaborn when you need:
โ Pretty visuals
โ Quick statistical summaries
โ Complex plots with little code
โ Multiple variables shown together
โ Ready-made styles
Donโt use Seaborn when:
โ You want absolute low-level control
โ Youโre making interactive dashboards (use Plotly)
๐ End of Chapter 1
Patlu: โBheem! When do we start drawing?โ
Bheem: โIn the next chapter, beta. Ready your samosas. We are doing line plots, bar plots, scatter plotsโฆ pura dhamaka!โ
๐ Welcome to Chapter 2 (Part 1) โ Basic Plots!
Professor Bheem & Patlu Pandit are back with more chaos, comedy, and colorful charts!
๐ CHAPTER 2 โ BASIC PLOTS (Part 1)
Functions Covered in This Part:
โ sns.lineplot
โ sns.scatterplot
โ sns.barplot
โ sns.countplot
๐ฏ๐ฅ Scene Intro
(The village fair of Dholakpur is happening. Bheem is calmly explaining data concepts, while Patlu Pandit chases a golgappa seller with a histogram board.)
Patlu: โBheem! Can seaborn make my life easy?โ
Bheem: โBetaโฆ seaborn toh sab ka life easy karta hai. Except the one who forgot to install it.โ
๐ผ๐ฅ๐ฟ๏ธ๐
๐จ 1. sns.lineplot() โ The โStory of Changeโ Plot
๐ Concept
Bheemโs Wisdom: โLine plots show how something changes over time, just like Patluโs weight after every samosa.โ
A line plot shows trends over a continuous variable (e.g., time, distance, years).
๐ญ Analogy
Imagine tracking how many laddus Bheem ate every hour.
Plot time vs. laddus โ you get a line showing โladdoo consumption trend.โ
๐ป Example 1: Simple Line Plot
import seaborn as sns
import matplotlib.pyplot as plt
data = {
"hour": [1, 2, 3, 4, 5],
"laddus_eaten": [5, 8, 12, 15, 20]
}
sns.lineplot(x="hour", y="laddus_eaten", data=data)
plt.title("Bheemโs Laddoo Consumption Over Time")
plt.show()
Output Preview
hour | laddus
----------------
1 | 5
2 | 8
3 | 12
4 | 15
5 | 20
Line goes upward ๐
๐ป Example 2: Lineplot with Multiple Categories (hue)
data = {
"hour": [1,1,2,2,3,3],
"count": [5,3,8,4,12,7],
"person": ["Bheem","Patlu","Bheem","Patlu","Bheem","Patlu"]
}
sns.lineplot(x="hour", y="count", hue="person", data=data)
plt.title("Bheem vs Patlu Eating Competition")
plt.show()
Preview
Two lines:
- Bheem: ๐
- Patlu: triesโฆ but stays low ๐ญ
Patlu: โBheem! I wasnโt ready that day!โ
Bheem: โBeta, even the lineplot knows the truth.โ
๐ผ๐ฅ๐ฟ๏ธ๐
๐ฏ 2. sns.scatterplot() โ The "Relationship Finder" Plot
๐ Concept
A scatterplot shows how two variables relate.
Bheemโs Wisdom: โDots are like villagers. Scatterplot shows who stands near whom.โ
๐ญ Analogy
Scatterplot is like a playgroundโkids randomly standing everywhere but forming hidden patterns.
๐ป Example 1: Simple Scatter Plot
data = {
"height": [110,120,130,140,150],
"strength": [30,40,50,60,80]
}
sns.scatterplot(x="height", y="strength", data=data)
plt.title("Height vs Strength in Dholakpur Kids")
plt.show()
Preview
Dots rising diagonally โ๏ธ
Height โ โ Strength โ
๐ป Example 2: Categorized Scatter Plot
data = {
"height": [110,120,130,140,150,115,125],
"strength": [30,40,50,60,80,20,25],
"group": ["BheemTeam","BheemTeam","BheemTeam","BheemTeam","BheemTeam","Villain","Villain"]
}
sns.scatterplot(x="height", y="strength", hue="group", s=120, data=data)
plt.title("Heroes vs Villains Strength Map")
plt.show()
Preview
Heroes = blue dots ๐ต
Villains = red dots ๐ด
Villains are weak ๐ญ
๐ผ๐ฅ๐ฟ๏ธ๐
๐ญ 3. sns.barplot() โ The โComparison Championโ Plot
๐ Concept
Barplot compares averages or values across categories.
Bheemโs Wisdom: โBars are laddus arranged neatlyโhigher bar = more laddus.โ
๐ญ Analogy
Imagine counting how many samosas each friend ate.
Draw bars for each โ instant comparison.
๐ป Example 1: Simple Bar Plot
data = {
"friend": ["Bheem","Chhutki","Jaggu","Patlu"],
"samosas": [10,4,3,1]
}
sns.barplot(x="friend", y="samosas", data=data)
plt.title("Samosa Eating Contest")
plt.show()
Preview
Bheem: โโโโโโโโ
Chhutki: โโโโ
Jaggu: โโโ
Patlu: โ
๐ป Example 2: Barplot with Hue
data = {
"day": ["Mon","Mon","Tue","Tue"],
"samosas": [10,5,7,3],
"group": ["Heroes","Villains","Heroes","Villains"]
}
sns.barplot(x="day", y="samosas", hue="group", data=data)
plt.title("Samosa Eating: Heroes vs Villains")
plt.show()
Preview
Mon: Heroes > Villains
Tue: Heroes > Villains
Always ๐
๐ผ๐ฅ๐ฟ๏ธ๐
๐ฌ 4. sns.countplot() โ The โFrequency Finderโ
๐ Concept
Countplot counts how many times each category appears.
Bheemโs Wisdom: โCountplot is a barplot that counts on its ownโlike Patlu counting his failed attempts.โ
๐ป Example 1: Count of Characters
data = ["Bheem","Bheem","Patlu","Chhutki","Bheem","Patlu"]
sns.countplot(x=data)
plt.title("Most Common Dholakpur Heroes")
plt.show()
Preview
Bheem: โโโโโ
Patlu: โโ
Chhutki: โ
๐ป Example 2: Countplot with Hue (2 categories)
import pandas as pd
df = pd.DataFrame({
"person": ["Bheem","Bheem","Patlu","Chhutki","Patlu","Bheem"],
"team": ["Hero","Hero","Sidekick","Hero","Sidekick","Hero"]
})
sns.countplot(x="person", hue="team", data=df)
plt.title("Hero vs Sidekick Count")
plt.show()
Preview
Person Hero | Sidekick
--------------------------
Bheem โโโ |
Patlu | โโ
Chhutki โ |
๐ผ๐ฅ๐ฟ๏ธ๐
๐ End of Chapter 2 (Part 1)
Patlu: โBheem! So many plotsโฆ my brain needs a chai break!โ
Bheem: โBeta, real break after Chapter 2. More plots ahead!โ
๐ Buckle up! Professor Bheem & Patlu Pandit return forโฆ
๐ CHAPTER 2 โ BASIC PLOTS (Part 2)
Functions Covered:
โ sns.histplot
โ sns.boxplot
โ sns.violinplot
(Scene: Patlu Pandit is hiding behind a giant potato heap. Bheem walks in with a laptop.)
Patlu: "Bheem! These plots sound scary! What if a histogram eats me?"
Bheem: โHistogram sirf data khaata haiโฆ Patlu jaise motu log nahi.โ
Patlu: โ๐ขโ
๐ผ๐ฅ๐ฟ๏ธ๐
๐จ 5. sns.histplot() โ The โShape of Dataโ Plot
๐ Concept
A histogram shows the distribution of a numeric variable.
It groups data into bins and counts how many points fall inside each bin.
Bheemโs Wisdom:
โHistogram is like counting how many laddus are small, medium, or large. More laddus = taller bar.โ
๐ญ Analogy
Imagine your mother sorting onion sizes in the kitchen:
Small onions โ 10
Medium โ 25
Large โ 5
Thatโs a histogram of onions!
๐ป Example 1: Simple Histogram
import seaborn as sns
import matplotlib.pyplot as plt
pop = [10,12,15,20,25,12,15,30,40,22,18,19]
sns.histplot(pop, bins=5, kde=False)
plt.title("Distribution of Patluโs Daily Chapatis")
plt.show()
Output Preview
Bin Range Count
-------------------
10โ16 โโโโ
16โ22 โโโโโโโโ
22โ28 โโ
28โ34 โ
34โ40 โ
๐ป Example 2: Histogram with KDE (Smooth Curve)
sns.histplot(pop, bins=5, kde=True, color="orange")
plt.title("Chapati Distribution with KDE")
plt.show()
Preview
Bars + smooth curve like a hill โฐ๏ธ
Patlu: โThat curve looks like my tummy shape!โ
Bheem: โExactly.โ
๐ผ๐ฅ๐ฟ๏ธ๐
๐ช 6. sns.boxplot() โ The โData Truth Detectorโ
๐ Concept
A boxplot shows:
Minimum
Q1 (25%)
Median
Q3 (75%)
Maximum
Outliers
Bheemโs Wisdom:
โBoxplot is like truth serum โ it exposes the outliers the way villagers expose Patluโs mistakes.โ
๐ญ Analogy
Imagine measuring how spicy samosas are:
Most are medium (inside the box)
One samosa is ultra-spicy (outlier)
โ That samosa will be a dot outside the plot.
๐ป Example 1: Simple Boxplot
data = [10,12,13,14,15,16,18,100] # 100 = outlier
sns.boxplot(data=data)
plt.title("Spice Level of Samosas")
plt.show()
Output Preview
Box โโ median: 15
Whiskers: 10 to 18
Outlier: 100 (Patluโs sambosa ๐ญ)
๐ป Example 2: Boxplot by Category
import pandas as pd
df = pd.DataFrame({
"team": ["Heroes","Heroes","Heroes","Villains","Villains"],
"strength": [80,85,90,40,35]
})
sns.boxplot(x="team", y="strength", data=df)
plt.title("Strength Comparison")
plt.show()
Preview
Heroes box: high values
Villains box: low; crying
๐ผ๐ฅ๐ฟ๏ธ๐
๐ป 7. sns.violinplot() โ The โMusical Distribution Plotโ
๐ Concept
A violinplot is like a boxplot + KDE curve.
Bheemโs Wisdom:
โWhen boxplot meets art, violinplot is born.โ
It shows:
Distribution shape
Density
Median
Thick-thin regions
Looks like: ๐ป
๐ญ Analogy
Imagine flipping a jalebi.
Thick parts = lots of data
Thin parts = fewer data
Thatโs violinplot.
๐ป Example 1: Basic Violin Plot
import seaborn as sns
vals = [10,12,12,14,15,16,18,18,19,40]
sns.violinplot(data=vals)
plt.title("Jalebi Size Distribution")
plt.show()
Output Preview
Wide bottom โ most jalebis medium size
Thin top โ few very large jalebis
Outliers are hidden inside density
๐ป Example 2: Violin Plot by Groups
import pandas as pd
df = pd.DataFrame({
"group": ["Kids","Kids","Kids","Adults","Adults","Adults"],
"laddus": [5,8,7,10,12,14]
})
sns.violinplot(x="group", y="laddus", data=df)
plt.title("Laddu Eating Capacity")
plt.show()
Preview
Kids violin is small
Adult violin is long
Patlu: โWhy is the violin not playing music?โ
Bheem: โBeta, plot haiโฆ piano nahi.โ
๐ผ๐ฅ๐ฟ๏ธ๐
๐ End of Chapter 2 (Part 2) ๐
Patlu: โBheem! These shapes look like musical instruments!โ
Bheem: โBeta, data bhi gaata haiโฆ if you know how to listen.โ
๐ CHAPTER 3 โ INTERMEDIATE PLOTS
Functions Covered in This Chapter:
โ sns.kdeplot
โ sns.jointplot
โ sns.pairplot
โ sns.lmplot
โ sns.heatmap
โ sns.clustermap
๐ฌ Scene Opening
(Bheem sits in a meditation pose, visualizing distributions. Patlu sneaks in with a bucket of pani puri.)
Patlu: โBheem! What is KDE? Some new pani puri flavor?โ
Bheem: โBetaโฆ KDE is a smooth distribution curve. Pani puri is distribution of chaos in your stomach.โ
Patlu: โOh.โ
๐ผ๐ฅ๐ฟ๏ธ๐
๐จ 1. sns.kdeplot() โ The โSmooth Mountainโ Plot
๐ Concept
A KDE Plot (Kernel Density Estimate) shows a smooth curve representing the probability distribution of data.
Bheemโs Wisdom:
โKDE is a histogram after drinking Glucon-D โ smooth and recharged!โ
๐ญ Analogy
Imagine flattening a pile of laddus into a smooth curve that shows where most laddus are concentrated.
๐ป Example 1: Simple KDE Plot
import seaborn as sns
import matplotlib.pyplot as plt
sweets = [10,12,13,14,15,18,16,15,14,13,12,50] # 50 = crazy outlier
sns.kdeplot(sweets)
plt.title("Sweetness Level Distribution")
plt.show()
Preview
Smooth hill-like curve โฐ๏ธ
Peak around 14-15
Tiny bump near 50 (Patlu ate it)
๐ป Example 2: Filled KDE Plot
sns.kdeplot(sweets, fill=True, color="purple")
plt.title("Sweetness Density (Filled)")
plt.show()
Preview
Looks like a colored mountain
Patlu: โThis looks tasty.โ
Bheem: โItโs data, not dessert."
๐ผ๐ฅ๐ฟ๏ธ๐
๐ 2. sns.jointplot() โ Combo Plot (Scatter + Histogram)
๐ Concept
Jointplot shows:
โ Relationship between two variables
โ Individual distributions for each variable
Bheemโs Wisdom:
โJointplot is like a full thali โ you get everything in one plate.โ
๐ป Example 1: Scatter + Histograms
sns.jointplot(x="height", y="strength",
data={"height":[120,130,140,150], "strength":[30,40,50,65]},
kind="scatter")
Preview
Center: scatterplot
Top: height histogram
Right: strength histogram
๐ป Example 2: Hexbin Jointplot (Honeycomb Style)
sns.jointplot(x="height", y="strength",
data={"height":[120,130,160,170,145,155],
"strength":[20,30,40,60,65,70]},
kind="hex")
Preview
Honeycomb cells โ density clusters
Patlu: โAre these beehives?โ
Bheem: โNo, they are your brain cells.โ
๐ผ๐ฅ๐ฟ๏ธ๐
๐ 3. sns.pairplot() โ The โEverything Everywhereโ Plot
๐ Concept
Pairplot creates multiple plots at once, showing pairwise relationships between all variables.
Bheemโs Wisdom:
โWhen data has multiple features, pairplot is like CCTV โ it watches every relationship.โ
๐ญ Analogy
Think of it as:
Every column goes on a coffee date
With every other column
And Seaborn clicks photos (plots)
๐ป Example 1: Simple Pairplot
import seaborn as sns
import pandas as pd
df = sns.load_dataset("iris") # classic dataset
sns.pairplot(df)
plt.show()
Preview
Grid of scatter + hist plots
Flowers comparing petal & sepal sizes
๐ป Example 2: Pairplot with Hue
sns.pairplot(df, hue="species")
plt.show()
Preview
Different species = different colors
Clear separation visible
๐ผ๐ฅ๐ฟ๏ธ๐
๐ฏ 4. sns.lmplot() โ The โPredict the Trendโ Plot
๐ Concept
lmplot draws a scatterplot with a regression line.
Bheemโs Wisdom:
โlmplot shows the trend, like predicting Patluโs next blunder.โ
๐ป Example 1: Simple lmplot
df = sns.load_dataset("tips")
sns.lmplot(x="total_bill", y="tip", data=df)
plt.show()
Preview
Dots + slanted line
Higher bill โ Higher tip
๐ป Example 2: lmplot with Hue
sns.lmplot(x="total_bill", y="tip", hue="sex", data=df)
plt.show()
Preview
Separate regression lines for Male/Female
๐ผ๐ฅ๐ฟ๏ธ๐
๐ฅ 5. sns.heatmap() โ The โTemperature Mapโ
๐ Concept
Heatmap shows values in a matrix as colored cells.
Bheemโs Wisdom:
โHeatmap is like a dosa tawa โ hotter parts are darker!โ
๐ป Example 1: Simple Heatmap
import numpy as np
mat = np.array([[1,4,6],[2,8,9],[3,5,7]])
sns.heatmap(mat, annot=True)
plt.show()
Preview
Number grid
Darker = bigger numbers
๐ป Example 2: Correlation Heatmap
df = sns.load_dataset("iris")
sns.heatmap(df.corr(), annot=True, cmap="coolwarm")
plt.show()
Preview
Red = strong positive
Blue = strong negative
๐ผ๐ฅ๐ฟ๏ธ๐
๐งฌ 6. sns.clustermap() โ The โFamily Tree of Dataโ
๐ Concept
Clustermap groups similar rows/columns based on similarity.
Bheemโs Wisdom:
โClustermap is like finding who in the village acts like whom. Patlu clusters far from everyone.โ
๐ป Example 1: Basic Clustermap
sns.clustermap(mat, cmap="viridis")
plt.show()
Preview
Rows & columns rearranged
Tree shown at top & left
๐ป Example 2: Clustermap with Z-Score Scaling
sns.clustermap(df.corr(), cmap="coolwarm", standard_scale=1)
plt.show()
Preview
Beautiful dendrogram hierarchy
๐ End of Chapter 3
Patlu: โBheem! These plots are smarter than me!โ
Bheem: โThatโs why they work.โ
๐ CHAPTER 4 โ Styling & Customization
๐ฌ Scene Opening
(Professor Bheem adjusts his glasses while Patlu Pandit stands with a paintbrush, trying to repaint a scatterplot.)
Patlu: โBheem! My graphs look like Government school blackboard. Help!โ
Bheem: โPatlu betaโฆ with Seaborn styling, even your report card will look premium.โ
Patlu: โWah! Make it look like a Karan Johar movie poster.โ
๐ผ๐ฅ๐ฟ๏ธ๐
๐จ 1. sns.set_theme() โ The โMake It Beautifulโ Button
๐ Concept
This sets the default theme for ALL Seaborn plots.
Bheemโs Wisdom:
โTheme sets the mood โ like lighting for a romantic song.โ
๐ญ Example Cartoon Analogy
Imagine upgrading from a tube light to fairy lights.
Everything suddenly looks beautiful.
Thatโs what set_theme does.
๐ป Example โ Apply Default Theme
sns.set_theme()
sns.lineplot(x=[1,2,3], y=[3,2,5])
plt.title("Theme Activated!")
plt.show()
Output Preview
Smooth fonts
Pleasant background
Better colors
๐ผ๐ฅ๐ฟ๏ธ๐
๐จ 2. sns.set_style() โ Dress Up the Plot
๐ Concept
Styles include:
"white""dark""whitegrid""darkgrid""ticks"
Patluโs Theory:
โWhitegrid = school notebook.โ
Bheem: โCorrect. Darkgrid = DJ night in Dholakpur.โ
๐ป Example
sns.set_style("whitegrid")
sns.histplot([1,2,2,3,3,3,4])
plt.show()
Preview
Clean white background
Light grey grid lines
๐ผ๐ฅ๐ฟ๏ธ๐
๐ 3. Color Palettes โ Paint the Town
๐ Concept
Seaborn palettes:
โ deep
โ muted
โ pastel
โ dark
โ colorblind
โ rocket, mako, flare, viridis
Bheemโs Wisdom:
โCorrect palette = correct vibes.โ
๐ญ Analogy
Choosing palettes is like choosing Holi colors.
Some are softโฆ some burn your eyesโฆ
Just donโt choose the one Patlu bought last Holi.
๐ป Example โ Use a Palette
sns.set_palette("pastel")
sns.barplot(x=["A","B","C"], y=[5,3,6])
plt.show()
Preview
Soft, beautiful pastel bars
๐ป Example โ Custom Colors
sns.set_palette(["#ff5733","#33c1ff","#75ff33"])
๐ผ๐ฅ๐ฟ๏ธ๐
๐ง 4. sns.set_context() โ Zoom In or Out
๐ Concept
Contexts adjust scale:
papernotebooktalkposter
Bheemโs Wisdom:
โPoster context = Dharmendra shouting dialogue on big screen.โ
๐ป Example
sns.set_context("poster")
sns.lineplot(x=[1,2,3], y=[10,20,30])
plt.title("BIG Plot Energy")
plt.show()
๐ผ๐ฅ๐ฟ๏ธ๐
๐ 5. Figure Size โ Make It Big or Small
๐ Concept
Use plt.figure(figsize=(width, height)).
๐ป Example
plt.figure(figsize=(10,5))
sns.scatterplot(x=[1,2,3], y=[4,5,6])
plt.show()
Preview
Wide plot
Perfect for presentations
๐ผ๐ฅ๐ฟ๏ธ๐
๐จ 6. Hue, Size, Style โ Intelligent Coloring
๐ Concept
Use for categorical separation:
hue="category"โ color groupssize="variable"โ dot size variesstyle="category"โ marker shapes
Bheem: โHue dikhaata hai kaun kis group mein.โ
Patlu: โLike school house colors!โ
๐ป Example
df = sns.load_dataset("tips")
sns.scatterplot(
x="total_bill",
y="tip",
hue="sex",
size="size",
style="time",
data=df
)
plt.show()
Preview
Colors = Male/Female
Sizes = table size
Shapes = Lunch/Dinner
๐ผ๐ฅ๐ฟ๏ธ๐
๐ 7. Adding Annotations
๐ Concept
Use plt.text() for labeling.
๐ป Example
sns.lineplot(x=[1,2,3], y=[5,10,7])
plt.text(2, 10, "Peak Value!", fontsize=12, color="red")
plt.show()
Preview
A text label appears at the peak
๐ End of Chapter 4 โ Styling Mastery Complete!
Patlu: โBheem! My plots look like Instagram posts now!โ
Bheem: โWait till you see the advanced tricksโฆโ
๐ CHAPTER 5 โ ADVANCED SEABORN TRICKS
This is where your plots gain superpowersโlike Chhota Bheem after eating 5 kg laddus.
๐ฌ Opening Scene
(Patlu is tangled inside a giant spiderweb made of subplots.)
Patlu: โBheem! Help! I tried making multiple plots and got stuck!โ
Bheem: โBeta, these are subplots, not spiderwebs. Relax.โ
Patlu: โThen why am I upside down?โ
Bheem: โBecause you clicked โrunโ without planning.โ
๐ผ๐ฅ๐ฟ๏ธ๐
๐ 1. FacetGrid โ Multiple Plots Automatically
๐ Concept
FacetGrid creates a grid of plots based on categories.
Itโs like splitting your data into different rooms.
Bheemโs Wisdom:
โFacetGrid is like separating Dholakpur villagers based on their favorite snacks.โ
๐ญ Analogy
Imagine 3 rooms:
Room 1 โ Samosa Lovers
Room 2 โ Jalebi Lovers
Room 3 โ Momos Lovers
FacetGrid makes one plot per room automatically.
๐ป Example 1: Simple FacetGrid
import seaborn as sns
import matplotlib.pyplot as plt
df = sns.load_dataset("tips")
g = sns.FacetGrid(df, col="sex")
g.map(sns.histplot, "total_bill")
plt.show()
Output Preview
Left Plot โ Female bills
Right Plot โ Male bills
๐ป Example 2: Row + Column Facets
g = sns.FacetGrid(df, row="time", col="sex")
g.map(sns.scatterplot, "total_bill", "tip")
plt.show()
Output Preview
4 plots:
Lunch/Female
Lunch/Male
Dinner/Female
Dinner/Male
๐ผ๐ฅ๐ฟ๏ธ๐
๐งฑ 2. Subplots โ Build Dashboards
๐ Concept
Use matplotlib plt.subplots() to create multiple axes.
๐ป Example: 1 Row, 2 Columns
fig, axes = plt.subplots(1, 2, figsize=(12, 5))
sns.histplot(df["total_bill"], ax=axes[0])
sns.scatterplot(x="total_bill", y="tip", data=df, ax=axes[1])
plt.show()
Preview
Left: histogram
Right: scatterplot
๐ญ Analogy
Subplots = Thali meal
Each plot = Different dish
Combined โ Full feast
Patlu: โMere plate mein jalebi bhi add karo!โ
Bheem: โAdd a pie chart later.โ
๐ผ๐ฅ๐ฟ๏ธ๐
๐ 3. Custom Colormaps โ Designer Color Themes
๐ Concept
Use:
sns.color_palette()sns.palplot()Matplotlib colormap names (viridis, plasma, etc.)
๐ป Example 1: Preview a Palette
sns.palplot(sns.color_palette("rocket"))
plt.show()
๐ป Example 2: Custom Colormap
sns.heatmap(df.corr(), cmap="viridis", annot=True)
plt.show()
Preview
Dark green โ Low value
Bright yellow โ High value
๐ผ๐ฅ๐ฟ๏ธ๐
๐ 4. Advanced Jointplots
๐ป Example 1: Regression Jointplot
sns.jointplot(x="total_bill", y="tip", data=df, kind="reg")
plt.show()
Preview
Scatter + Regression + Histograms
๐ป Example 2: KDE Jointplot
sns.jointplot(x="total_bill", y="tip", data=df, kind="kde")
plt.show()
Preview
Beautiful contour lines
Looks like topographic map
๐ผ๐ฅ๐ฟ๏ธ๐
๐ 5. Statistical Visualizations with Seaborn
๐ Concept
Use:
Confidence Intervals
Error Bars
Estimators
Seaborn automatically computes statistics.
๐ป Example: Barplot averages + CI
sns.barplot(x="sex", y="tip", data=df, ci=95)
plt.show()
Preview
Bars + thin line on top = 95% confidence
๐ผ๐ฅ๐ฟ๏ธ๐
๐ 6. Multi-Panel Dashboards
๐ Concept
Combine:
subplots
multiple seaborn functions
styling
๐ป Example: 4-Plot Dashboard
fig, axes = plt.subplots(2, 2, figsize=(12, 10))
sns.histplot(df["tip"], ax=axes[0,0])
sns.scatterplot(x="total_bill", y="tip", data=df, ax=axes[0,1])
sns.boxplot(x="day", y="tip", data=df, ax=axes[1,0])
sns.lineplot(x="total_bill", y="tip", data=df, ax=axes[1,1])
plt.tight_layout()
plt.show()
Preview
4 neat plots arranged in 2ร2
Looks like a professional dashboard
๐ผ๐ฅ๐ฟ๏ธ๐
๐ End of Chapter 5 โ You Are Now an Advanced Seaborn Ninja!
Patlu: โBheem! My plots now look like Netflix thumbnails!โ
Bheem: โBetaโฆ wait till you combine everything in real-life projects.โ
๐ CHAPTER 6 โ REAL PROJECTS (END-TO-END)
Projects Covered:
IPL Analytics Dashboard
Zomato Delivery Time Visualization
Indian Climate / Temperature Analysis
๐ฌ Scene Opening
(Patlu Pandit walks in with a cricket bat, a Zomato helmet, and an umbrella.)
Bheem: โBeta, why are you dressed like you got lost in three different jobs?โ
Patlu: โBheemโฆ you said today we are doing 3 projects!โ
Bheem: โArre wah! At least you're prepared once in your life.โ
๐ผ๐ฅ๐ฟ๏ธ๐
๐ PROJECT 1 โ IPL Analytics Dashboard
(Scene: Bheem wearing an IPL jersey, Patlu selling fake popcorn outside the stadium.)
๐ Goal
Analyze IPL batting performance using seaborn visualizations.
Dataset columns we assume:
| Column | Description |
| player | Player name |
| runs | Runs scored |
| strike_rate | Strike rate |
| balls | Balls faced |
| team | Team name |
๐ญ Step 1 โ Load the Dataset
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
df = pd.read_csv("ipl_batting.csv")
๐ฏ Step 2 โ Most Runs (Top Scorers)
top = df.groupby("player")["runs"].sum().sort_values(ascending=False).head(10)
sns.barplot(x=top.values, y=top.index, palette="viridis")
plt.title("Top 10 Run Scorers in IPL")
plt.show()
Preview
Long bars = legends
Short bars = Patlu-level players
๐ฏ Step 3 โ Strike Rate Distribution
sns.histplot(df["strike_rate"], bins=20, kde=True)
plt.title("Strike Rate Distribution")
plt.show()
๐ฏ Step 4 โ Teamwise Batting Performance
sns.boxplot(x="team", y="runs", data=df)
plt.xticks(rotation=45)
plt.title("Runs by Team")
plt.show()
๐ฏ Step 5 โ Pairplot for Deep Insight
sns.pairplot(df[["runs","balls","strike_rate"]])
plt.show()
๐ End of Project 1
Patlu: โBheem! Now I know why RCB fans cry every year.โ
Bheem: โBetaโฆ some mysteries even Seaborn cannot solve.โ
๐ผ๐ฅ๐ฟ๏ธ๐
๐ PROJECT 2 โ Zomato Delivery Time Visualization
(Scene: Patlu dressed as a Zomato rider, late as usual.)
Patlu: โBheem! My delivery got delayed because a cow was sitting on the road!โ
Bheem: โZomato should track your excuses as features.โ
๐ Goal
Understand delivery time patterns.
Dataset columns we assume:
| Column | Description |
| order_id | Order number |
| delivery_time | Minutes taken |
| distance_km | Distance |
| weather | Weather conditions |
| traffic | Traffic level |
๐ฏ Step 1 โ Load the Data
df = pd.read_csv("zomato_delivery.csv")
๐ฏ Step 2 โ Delivery Time Distribution
sns.histplot(df["delivery_time"], bins=20, kde=True, color="red")
plt.title("Delivery Time Distribution")
plt.show()
๐ฏ Step 3 โ Effect of Traffic
sns.boxplot(x="traffic", y="delivery_time", data=df)
plt.title("Traffic vs Delivery Time")
plt.show()
Preview
Heavy traffic โ tall box โ long delays
๐ฏ Step 4 โ Weather Impact
sns.barplot(x="weather", y="delivery_time", data=df, estimator="mean")
plt.title("Weather-wise Delivery Time")
plt.show()
๐ฏ Step 5 โ Distance vs Delivery Time (Regression)
sns.lmplot(x="distance_km", y="delivery_time", data=df)
plt.title("Distance vs Time")
plt.show()
๐ End of Project 2
Patlu: โBheem! According to regression, my delivery should take 15 minutes!โ
Bheem: โBetaโฆ model predicted delivery, not your stupidity.โ
๐ผ๐ฅ๐ฟ๏ธ๐
๐ PROJECT 3 โ Indian Climate / Temperature Analysis
(Scene: Patlu sweating in Chennai, freezing in Shimla, and getting drenched in Kerala.)
๐ Goal
Analyze temperature trends across Indian cities.
Dataset columns:
| Column | Description |
| city | City name |
| month | Month number |
| temperature | Average temp |
| humidity | Average humidity |
๐ฏ Step 1 โ Load Data
df = pd.read_csv("india_climate.csv")
๐ฏ Step 2 โ Temperature Distribution
sns.kdeplot(df["temperature"], fill=True, color="orange")
plt.title("Temperature Distribution in India")
plt.show()
๐ฏ Step 3 โ Citywise Temperature
sns.boxplot(x="city", y="temperature", data=df)
plt.xticks(rotation=45)
plt.title("Citywise Temperature")
plt.show()
๐ฏ Step 4 โ Monthwise Climate Trend
sns.lineplot(x="month", y="temperature", hue="city", data=df)
plt.title("Monthly Temperature Trend")
plt.show()
๐ฏ Step 5 โ Heatmap of City vs Month
pivot = df.pivot_table(values="temperature", index="city", columns="month")
sns.heatmap(pivot, cmap="coolwarm", annot=True)
plt.title("City-Month Temperature Heatmap")
plt.show()
๐ End of Project 3
Patlu: โBheem, which city should I settle in?โ
Bheem: โBetaโฆ based on your heatmap, Antarctica is perfect for you.โ
