Sunday, 1 March 2026

๐ŸŒ„ Day 43: Ridge Plot in Python

 

๐ŸŒ„ Day 43: Ridge Plot in Python

On Day 43 of our Data Visualization journey, we created a beautiful and modern Ridge Plot (Joy Plot) using Plotly in Python.

Ridge plots are perfect when you want to compare distributions across multiple categories — while keeping the visualization smooth and visually engaging.

Today’s example visualizes Sales Distribution by Month from January to May.

๐ŸŽฏ What is a Ridge Plot?

A Ridge Plot is a series of overlapping density plots stacked vertically.

It helps you:

  • Compare distributions across categories

  • Identify trends over time

  • Spot shifts in data patterns

  • Understand spread and concentration

It’s especially popular in:

  • Time-series distribution analysis

  • Financial data

  • Sales performance tracking

  • Experimental comparisons


๐Ÿ“Š What We’re Visualizing

We simulated monthly sales data for:

  • Jan

  • Feb

  • Mar

  • Apr

  • May

Each month has its own distribution curve, showing how sales values are spread.


๐Ÿง‘‍๐Ÿ’ป Python Implementation (Plotly)


✅ Step 1: Import Libraries

import numpy as np
import plotly.graph_objects as go


  • NumPy → Generate sample distribution data

  • Plotly → Create smooth violin-based ridge effect


✅ Step 2: Set Random Seed

np.random.seed(42)

This ensures reproducible results.


✅ Step 3: Define Months & Colors

months = ["Jan", "Feb", "Mar", "Apr", "May"]
colors = ["#A3B18A", "#588157", "#3A5A40", "#BC6C25", "#DDA15E"]

We use earthy, muted tones for a clean aesthetic look.


✅ Step 4: Create Ridge Plot Using Violin Traces

fig = go.Figure() for i, month in enumerate(months): data = np.random.normal(loc=i*5, scale=2, size=200)
fig.add_trace(go.Violin( x=data, y=[month]*len(data), orientation='h', line_color=colors[i],
fillcolor=colors[i],
opacity=0.6, showlegend=False
))

How This Works:

  • np.random.normal() generates distribution data

  • Each month shifts slightly using loc=i*5

  • Horizontal violins mimic ridge effect

  • Transparency creates layered visual flow


✅ Step 5: Layout Styling

fig.update_layout(
title="Sales Distribution by Month (Ridge Plot)",
paper_bgcolor="#FAF9F6",
plot_bgcolor="#FAF9F6",
font_family="serif",
width=900,
height=500 )

✨ Design Highlights:

  • Soft linen background

  • Serif typography

  • Horizontal layout

  • Clean spacing

  • Modern pastel-earth palette


๐Ÿ“ˆ What the Ridge Plot Shows

  • January has lower average sales

  • Sales gradually increase toward May

  • May shows the highest concentration of values

  • Each month’s distribution spreads differently

Instead of just showing averages, the ridge plot shows:

✔ Shape of distribution
✔ Spread of values
✔ Density concentration
✔ Trend shifts over time


๐Ÿ’ก Why Use a Ridge Plot?

✔ Compare multiple distributions at once
✔ Visually appealing and modern
✔ Better than stacked histograms
✔ Ideal for storytelling dashboards
✔ Great for trend-based analysis


๐Ÿ”ฅ When to Use Ridge Plots

  • Monthly revenue distribution

  • Customer spending patterns

  • Test score distributions by class

  • Stock returns over time

  • Performance metrics comparison


๐Ÿš€ Day 43 Key Takeaway

Averages don’t tell the full story.

Ridge plots show:

  • Variation

  • Patterns

  • Trends

  • Distribution shape

0 Comments:

Post a Comment

Popular Posts

Categories

100 Python Programs for Beginner (119) AI (214) 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 (2) Data Analysis (26) Data Analytics (20) data management (15) Data Science (311) Data Strucures (16) Deep Learning (129) Django (16) Downloads (3) edx (21) Engineering (15) Euron (30) Events (7) Excel (18) 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 (256) Meta (24) MICHIGAN (5) microsoft (11) Nvidia (8) Pandas (13) PHP (20) Projects (32) Python (1260) Python Coding Challenge (1056) Python Mistakes (50) Python Quiz (433) 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)