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