VOOZH about

URL: https://www.geeksforgeeks.org/python/multiple-density-plots-with-pandas-in-python/

⇱ Multiple Density Plots with Pandas in Python - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Multiple Density Plots with Pandas in Python

Last Updated : 23 Jul, 2025

Multiple density plots are a great way of comparing the distribution of multiple groups in your data.  We can make multiple density plots using pandas plot.density() function. However, we need to convert data in a wide format if we are using the density function. Wide data represents different groups in different columns. We convert data in a wide format using Pandas pivot() function.

Let's create the simple data-frame and then reshape it into a wide-format:

Example 1:

Here we are using this data set.

Step 1: Creating dataframe from data set.

Output: 

👁 Image
dataset

Step 2: Let's group data according to countries in different columns so that we can apply the density() function to plot multiple density plots.

Output: 

👁 Image

Step 3: Now let's plot multiple density plot using plot.density()

Output :

👁 Image
Multiple density plots

Example 2: We can also call plot.kde() function on dataframe to make multiple density plots with Pandas.

Here we are using the tips dataset for this example, You can find it here.

Step 1: Creating dataframe from data set.

Output:

👁 Image
tips_df

Step 2: Now apply pivot() function to have dataframe in the wide-format then apply kde() to have multiple density plot. 

Output:

👁 Image
tips multiple D.P
Comment