Skip to main content

Command Palette

Search for a command to run...

๐ŸŽจ๐Ÿฏ Professor Bheem & Patlu Panditโ€™s Seaborn Safari!

Updated
โ€ข20 min readโ€ขView as Markdown

๐ŸŒŸ 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:

  • paper

  • notebook

  • talk

  • poster

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 groups

  • size="variable" โ†’ dot size varies

  • style="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:

  1. IPL Analytics Dashboard

  2. Zomato Delivery Time Visualization

  3. 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:

ColumnDescription
playerPlayer name
runsRuns scored
strike_rateStrike rate
ballsBalls faced
teamTeam 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:

ColumnDescription
order_idOrder number
delivery_timeMinutes taken
distance_kmDistance
weatherWeather conditions
trafficTraffic 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:

ColumnDescription
cityCity name
monthMonth number
temperatureAverage temp
humidityAverage 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.โ€