Joy Plots Visualization in Python [Easy Guide]

Filed Under: Python Modules
Joy Plots Python

In this tutorial, will be discussing a rare type of plot known as Joy Plots using the JoyPy library. The library is an open-source python library that is used to create Joy Plots.

Introduction to Joy Plots in Python

Ridgeline Plot or Joy Plot is a kind of chart that helps visualize distributions of several groups of a category in a dataset. Each category produces a density curve overlapping with each other which ends up creating a beautiful piece of the plot. One of many popular use cases of the Joy Chart is computing the numerical variable trend with time. 

Implementing Joy Plots in Python

We will start by installing a JoyPy library by using the pip command below.

pip install joypy

We will be importing the modules using the code below. For the datasets, we will be using the seaborn tips dataset in the later section.

import joypy
import seaborn as sns

Also Read: Data Visualization with Python Seaborn and Pandas

Loading the Dataset

For this article, we will make use of the famous Tips dataset which is already present in the seaborn library.

DATA = sns.load_dataset('tips')
print(DATA)
Tips Dataset Seaborn
Tips Dataset Seaborn

Creating Basic Joy Plots

Now we will start by creating different types of plots using different columns of the dataset of the previous section. Look at the code below.

joypy.joyplot(DATA)
Basic Joy Plot Tips Dataset
Basic Joy Plot Tips Dataset

Plotting on the Basis of a Column

We can also look at how the data is distributed on the basis of a single column using the code below. We will be seeing the distribution on the basis of the gender of the person.

joypy.joyplot(DATA, by="sex")
Basic Joy Plot Tips Gender Basis
Basic Joy Plot Tips Gender Basis

Customize Plot Colours and Fade Attribute

We can add the fade option to the Joy Plot to visualize overlapping density curves more clearly and also give colour to all the density curves. Look at the code and output below!

joypy.joyplot(DATA, by = 'day', color = 'Orange', fade = True)
Customized Joy Plot Tips Dataset
Customized Joy Plot Tips Dataset

We can also specify the colormap instead of a solid color using the code below. Look at the visual plot as well!

from matplotlib import cm
joypy.joyplot(DATA, by = 'day', colormap=cm.autumn, fade = True)
ColorMap Added Joy Plot Tips Dataset
ColorMap Added Joy Plot Tips Dataset

Customizing Joy Plots Layout and Size

We can change the range_style to make the y-axis visible for the width of the curve and also set the figure size as well. Look at the code below.

joypy.joyplot(DATA, by = 'sex', colormap = cm.autumn, fade = True,
              range_style='own', figsize = (10,6))
Layout Changed Plot Tips Dataset
Layout Changed Joy Plot Tips Dataset

Conclusion

In this article, we learned about Joy Plots, and how to plot them in Python. We also learned how to beautify and customize our plots to maximize the information we gain from the plots.

Hope you liked the tutorial! Thank you for reading!

close
Generic selectors
Exact matches only
Search in title
Search in content