VOOZH about

URL: https://www.analyticsvidhya.com/blog/2021/06/ridgeline-plots-visualize-data-with-a-joy/

⇱ Ridgeline Plots: Visualize Data with a Joy! | What is Ridgeline Plot?


India's Most Futuristic AI Conference Is Back – Bigger, Sharper, Bolder

  • d
  • :
  • h
  • :
  • m
  • :
  • s

Ridgeline Plots: Visualize Data with a Joy!

Rahul Shah Last Updated : 22 Oct, 2024
6 min read

This article was published as a part of the Data Science Blogathon

Introduction

The DIstribution of data plays an important role in model building. By visualizing the data, one can create an inference of what type of distribution the data is representing. Since a lot of statistical tests require the data to be normally distributed, it’s always beneficial to work towards normally distributing the data. Distribution plots also help to identify and treat outliers. One can get a rough estimate of the spread of the data based on the distribution.

Python has several libraries and function to visualize the distribution of data. One of the widely used plots for plotting the distribution is Histogram. What if we want to visualize the distribution of each class of a categorical variable. In this article, we will learn how to plot a Ridgeline Plot.

πŸ‘ Ridgeline Plots image

Image by Lukas from Pexels

Table of Contents

  1. Introduction
  2. Plot Ridgeline Plot in Python
  3. Beautifying the Ridgelines Plot
  4. Conclusions

Introduction

Ridgeline Plot or Joy Plot is a kind of chart that is used to visualize distributions of several groups of a category. Each category or group of a category produces a density curve overlapping with each other creating a beautiful piece of the plot. Joyplot got its name from the album cover Unknown Pleasue by Joy Division in 1979. Joy Plots are widely used in cases when we have a large number of classes or groups in a category. Wvwnhtugh, it may become cluttery but the plot as a whole becomes beautiful and meaningful at the same time. These plots have classes or groups at the y-axis while the numerical feature at the x-axis.

One of the popular use cases of the Ridgeline Chart is measuring the numerical variable with time. For example, we can measure the temperature for the last ten years. Here, it will create 10 horizontal liens for 10 classes and each class will plot a distribution of temperature throughout that year. This will help us gain insights about that year as well as analyzing the trend for the last 10 years. Interestingly, one may find the distribution of temperature has increased in comparison to the temperature we had 10 years ago.

In this article, we will build a Ridgeline Plot in Python using Python library joypy.

 

Plot Ridgeline Plot in Python

A Ridgeline Plot in Python can be built using several libraries including the mainstream Matplotlib and Plotly libraries. But plotting a Ridgeline Plot using joypy is pretty straightforward. Thus, we will continue with joypy for this article. 

 

Install the Required Libraries

!pip install joypy

 

Importing the Libraries

import pandas as pd
from joypy import joyplot
import matplotlib.pyplot as plt

Reading the Dataset

df = pd.read_csv("Admission_Predict.csv")

Here we are taking the Dataset built for the prediction of Admission to Graduate Courses from given parameters specifically for Indian students. The dataset has been downloaded from Kaggle.

For this article, we will try to plot the Ridgeline Plot for University Rating based on CGPA.

Conversion of University Rating

print(df.info())

On getting the info, we found that this dataset has not categorical column. We want the University Rating for the plot. Thus, we will concert the University Rating values into str type.

df_new['University Rating'] = df_new['University Rating'].astype(str)

Plotting the Ridgeline Plot

.joyplot() requires just one mandatory argument. But here, we will specify the β€˜by’ and β€˜col’ parameter as well.

Python Code:

import pandas as pd
from joypy import joyplot
import matplotlib.pyplot as plt

df = pd.read_csv("Admission_Predict.csv")

print(df.info())

df['University Rating'] = df['University Rating'].astype(str)


joyplot(df, by = 'University Rating', column = 'CGPA')
plt.xlabel("CGPA")
plt.show()

We can create a quick interpretation that as we move from University Ratings 1 to 5, the distribution of the CGPA is also shifting towards the right. Thus, a higher rating University requires a higher CGPA. Also, few outliers are present in the data as we see the density curve is stretching ahead of the 10 CGPA mark and CGPA never exceeds the value of 10.

Beautifying the Ridgelines Plot

In the previous section, we plotted a basic Ridgeline Plot. But a plot of beautification can be done to this chart as well, thanks to the number of arguments .joyplot() accepts. Let’s see a few of them:

1. Customize Plot Colours and Fade

We can add the fade option to the Ridgeline Plot to visualize overlapping density curves more clearly and aesthetically. We can give a mono colour to all the density curves using colour or can give a colour map to the curves sing cmap. Let’s visualize the plot using these changes:

joyplot(df, by = 'University Rating', column = 'CGPA', color = 'Orange', fade = True)
plt.show()

On executing this code, we get:

πŸ‘ Ridgeline Plots customize

Image Source – Personal Computer

Or, we can specify the colormap instead of color We can import the cm function from the matplotlib library:

from matplotlib import cm

joyplot(df, by = 'University Rating', column = 'CGPA', colormap=cm.autumn, fade = True)

plt.show()

On executing this code, we get:

πŸ‘ Ridgeline Plots matplotlib

Image Source – Personal Computer

 

2. Customize Plot Layout

We can change the range_style to β€˜own’ to make the y-axis visible for the width of the density curve only. Also, can set the figure size by passing a tuple of size values. Also, we can set the title to the Ridgeline Plot as an argument.

joyplot(df, by = 'University Rating', column = 'CGPA', colormap = cm.autumn, fade = True, 

 range_style='own', figsize = (10,6))

plt.show()

On executing this code, we get:

πŸ‘ Ridgeline Plots plot layout

Image Source – Personal Computer

 

3. Adding title to Ridgeline Plot

joyplot(df, by = 'University Rating', column = 'CGPA', colormap = cm.autumn, fade = True, 

 range_style='own', figsize = (10,6),

 title = 'Distribution of Student CGPA based on University Rating')

plt.show()

On executing this code, we get:

πŸ‘ title

Image Source – Personal Computer

 

4. Plot Histogram instead of Density Curve

Instead of plotting a Density Curve on each axis of the Ridgeline Plot, we can plot a histogram.

joyplot(df, by = 'University Rating', column = 'CGPA', color = 'Orange', fade = True, 
                range_style='own', figsize = (10,6), hist = True, overlap = 0,
                   title = 'Distribution of Student CGPA based on University Rating')
plt.show()

On executing this code, we get:

πŸ‘ Plot Histogram instead of Density Curve

Image Source – Personal Computer

Here, we have plotted a histogram for each University Rating. Also, we have specified the overlap value to 0. This will keep the group axes separated from one another.

Conclusions

In this article, we learned about Ridgeline Plot, also known as Joy Plots, and how to plot them in Python. We also learnt how to beautify our plots to maximise the information gain. There several other variations of Ridgeline Plots that are possible with the use of parameters of .joyplot(). The data is not cleaned and one can identify outliers from the plot as few of the curves are crossing CGPA value 10 and CGPA cannot exceed 10. As mentioned, RIdgeline Plot can accommodate a huge number of groups of a  categorical variable. Plotting a histogram instead of a density curve is not a popular option but it’s always good to know more. Ridgelines Plots are also possible to draw in other BI Tools such as Tableau or with other libraries such as Plotly. One can try plotting different Ridgelines on the same dataset using different Numerical Features or with different combinations of Categorical and numerical features.

About the Author

Connect with me on LinkedIn Here.

Check out my other Articles Here

You can provide your valuable feedback to me on LinkedIn.

Thanks for giving your time!

The media shown in this article are not owned by Analytics Vidhya and are used at the Author’s discretion.

IT Engineering Graduate currently pursuing Post Graduate Diploma in Data Science.

Login to continue reading and enjoy expert-curated content.

Free Courses

Exploratory Data Analysis with Python & GenAI

Learn EDA with Python: Transform data into insights using PandasAI & more.

Analyzing Data with Power BI

Turn raw data into insights with Power BI - dashboards, reports & more!

Responses From Readers

Flagship Programs

GenAI Pinnacle Program| GenAI Pinnacle Plus Program| AI/ML BlackBelt Program| Agentic AI Pioneer Program

Free Courses

Generative AI| DeepSeek| OpenAI Agent SDK| LLM Applications using Prompt Engineering| DeepSeek from Scratch| Stability.AI| SSM & MAMBA| RAG Systems using LlamaIndex| Building LLMs for Code| Python| Microsoft Excel| Machine Learning| Deep Learning| Mastering Multimodal RAG| Introduction to Transformer Model| Bagging & Boosting| Loan Prediction| Time Series Forecasting| Tableau| Business Analytics| Vibe Coding in Windsurf| Model Deployment using FastAPI| Building Data Analyst AI Agent| Getting started with OpenAI o3-mini| Introduction to Transformers and Attention Mechanisms

Popular Categories

AI Agents| Generative AI| Prompt Engineering| Generative AI Application| News| Technical Guides| AI Tools| Interview Preparation| Research Papers| Success Stories| Quiz| Use Cases| Listicles

Generative AI Tools and Techniques

GANs| VAEs| Transformers| StyleGAN| Pix2Pix| Autoencoders| GPT| BERT| Word2Vec| LSTM| Attention Mechanisms| Diffusion Models| LLMs| SLMs| Encoder Decoder Models| Prompt Engineering| LangChain| LlamaIndex| RAG| Fine-tuning| LangChain AI Agent| Multimodal Models| RNNs| DCGAN| ProGAN| Text-to-Image Models| DDPM| Document Question Answering| Imagen| T5 (Text-to-Text Transfer Transformer)| Seq2seq Models| WaveNet| Attention Is All You Need (Transformer Architecture) | WindSurf| Cursor

Popular GenAI Models

Llama 4| Llama 3.1| GPT 4.5| GPT 4.1| GPT 4o| o3-mini| Sora| DeepSeek R1| DeepSeek V3| Janus Pro| Veo 2| Gemini 2.5 Pro| Gemini 2.0| Gemma 3| Claude Sonnet 3.7| Claude 3.5 Sonnet| Phi 4| Phi 3.5| Mistral Small 3.1| Mistral NeMo| Mistral-7b| Bedrock| Vertex AI| Qwen QwQ 32B| Qwen 2| Qwen 2.5 VL| Qwen Chat| Grok 3

AI Development Frameworks

n8n| LangChain| Agent SDK| A2A by Google| SmolAgents| LangGraph| CrewAI| Agno| LangFlow| AutoGen| LlamaIndex| Swarm| AutoGPT

Data Science Tools and Techniques

Python| R| SQL| Jupyter Notebooks| TensorFlow| Scikit-learn| PyTorch| Tableau| Apache Spark| Matplotlib| Seaborn| Pandas| Hadoop| Docker| Git| Keras| Apache Kafka| AWS| NLP| Random Forest| Computer Vision| Data Visualization| Data Exploration| Big Data| Common Machine Learning Algorithms| Machine Learning| Google Data Science Agent
πŸ‘ Av Logo White

Continue your learning for FREE

Forgot your password?
πŸ‘ Av Logo White

Enter OTP sent to

Edit

Wrong OTP.

Enter the OTP

Resend OTP

Resend OTP in 45s

πŸ‘ Popup Banner
πŸ‘ AI Popup Banner