Monday, 9 March 2026

Day 49: Strip Plot in Python 📊

 

Day 49: Strip Plot in Python 📊

A Strip Plot is a simple yet powerful visualization used to display individual data points across categories. It is especially useful when you want to see the distribution of values while keeping every observation visible.

Unlike aggregated charts like bar plots or box plots, a strip plot shows each data point, making it easier to understand how values are spread within a category.

In this example, we visualize daily spending patterns using the Tips dataset.


📊 What is a Strip Plot?

A Strip Plot is a categorical scatter plot where:

  • One axis represents categories

  • The other axis represents numeric values

  • Each dot represents one observation

To avoid overlapping points, the plot can use jitter, which slightly spreads points horizontally.

This helps reveal patterns that would otherwise be hidden if the points stacked directly on top of each other.


📁 Dataset Used

This example uses the Tips dataset from Seaborn, which contains information about restaurant bills and tips.

Some important columns in the dataset include:

  • total_bill → Total amount spent

  • tip → Tip given

  • day → Day of the week

  • time → Lunch or dinner

In this visualization, we focus on:

  • Day of the week

  • Total bill amount


💻 Python Code

import seaborn as sns
import matplotlib.pyplot as plt

sns.set_theme(style="white", font='serif')
plt.figure(figsize=(10, 6), facecolor='#FAF9F6')

df = sns.load_dataset("tips")

ax = sns.stripplot(
x="day",
y="total_bill",
data=df,
jitter=0.25,
size=8,
alpha=0.6,
palette=["#E5989B", "#B5838D", "#6D6875", "#DBC1AD"]
)

ax.set_facecolor("#FAF9F6")
sns.despine(left=True, bottom=True)

plt.title("Daily Spending Flow", fontsize=18, pad=20, color='#4A4A4A')
plt.xlabel("")
plt.ylabel("Amount ($)", fontsize=12, color='#6D6875')

plt.show()

🔎 Code Explanation

1️⃣ Import Libraries

We import the required libraries:

  • Seaborn → for statistical data visualization

  • Matplotlib → for plotting and customization


2️⃣ Set the Visual Style

sns.set_theme(style="white", font='serif')

This gives the plot a clean editorial-style appearance with a serif font.


3️⃣ Load the Dataset

df = sns.load_dataset("tips")

This loads the built-in tips dataset from Seaborn.


4️⃣ Create the Strip Plot

sns.stripplot(x="day", y="total_bill", data=df, jitter=0.25)

Here:

  • x-axis → Day of the week

  • y-axis → Total bill amount

  • jitter spreads points slightly to avoid overlap

Each point represents one customer's bill.


5️⃣ Improve Visual Appearance

The code also customizes:

  • Background color

  • Color palette

  • Title and labels

  • Removed extra axis lines using sns.despine()

This creates a clean, modern-looking chart.


📈 Insights from the Plot

From the visualization we can observe:

  • Saturday and Sunday have more data points, meaning more restaurant visits.

  • Bills on weekends tend to be higher compared to weekdays.

  • Thursday and Friday have fewer observations and generally lower spending.

This helps quickly identify spending patterns across days.


🚀 When Should You Use a Strip Plot?

Strip plots are useful when you want to:

  • Show individual observations

  • Visualize data distribution across categories

  • Explore patterns in small to medium datasets

  • Perform exploratory data analysis

They are often used in data science, statistics, and exploratory analysis.


🎯 Conclusion

A Strip Plot is one of the simplest ways to visualize categorical distributions while keeping every data point visible. By adding jitter, it prevents overlap and clearly shows how values are distributed within each category.

Using Seaborn in Python, creating a strip plot becomes easy and visually appealing. In this example, we explored daily spending patterns and discovered clear differences between weekday and weekend restaurant bills.

0 Comments:

Post a Comment

Popular Posts

Categories

100 Python Programs for Beginner (119) AI (215) Android (25) AngularJS (1) Api (7) Assembly Language (2) aws (28) Azure (9) BI (10) Books (262) Bootcamp (1) C (78) C# (12) C++ (83) Course (86) Coursera (300) Cybersecurity (29) data (4) Data Analysis (27) Data Analytics (20) data management (15) Data Science (318) Data Strucures (16) Deep Learning (130) Django (16) Downloads (3) edx (21) Engineering (15) Euron (30) Events (7) Excel (19) Finance (10) flask (3) flutter (1) FPL (17) Generative AI (65) Git (10) Google (50) Hadoop (3) HTML Quiz (1) HTML&CSS (48) IBM (41) IoT (3) IS (25) Java (99) Leet Code (4) Machine Learning (258) Meta (24) MICHIGAN (5) microsoft (11) Nvidia (8) Pandas (13) PHP (20) Projects (32) Python (1263) Python Coding Challenge (1068) Python Mistakes (50) Python Quiz (438) Python Tips (5) Questions (3) R (72) React (7) Scripting (3) security (4) Selenium Webdriver (4) Software (19) SQL (46) Udemy (17) UX Research (1) web application (11) Web development (8) web scraping (3)

Followers

Python Coding for Kids ( Free Demo for Everyone)