Multiple Density Plots with Pandas in Python Last Updated : 03 Jan, 2021 Comments Improve Suggest changes Like Article Like Report 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. Python3 import pandas as pd # creating a dataframe df = pd.read_csv(r"gapminder1.csv") df.head() Output: 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. Python3 # converting data into wide-format data_wide = df.pivot(columns='continent', values='lifeExp') data_wide.head() Output: Step 3: Now let's plot multiple density plot using plot.density() Python3 import matplotlib.pyplot as plt # calling density() to make # multiple density plot data_wide.plot.density(figsize = (7, 7), linewidth = 4) plt.xlabel("life_Exp") Output : 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. Python3 import pandas as pd # creating a dataframe df = pd.read_csv(r"tips.csv") df.head() Output: tips_df Step 2: Now apply pivot() function to have dataframe in the wide-format then apply kde() to have multiple density plot. Python3 # Converting to wide dataframe data_wide = df.pivot(columns = 'day', values = 'total_bill') # plotting multiple density plot data_wide.plot.kde(figsize = (8, 6), linewidth = 4) Output: tips multiple D.P Comment More infoAdvertise with us Next Article Multiple Density Plots with Pandas in Python T tejalkadam18m Follow Improve Article Tags : Python Python-pandas Python pandas-plotting Practice Tags : python Similar Reads Adding Legend to Boxplot with Multiple Plots Boxplots are an effective way to visualize the distribution of a dataset. When analyzing multiple datasets simultaneously, it can become challenging to differentiate between them without a clear legend. This article will guide you through the process of adding a legend to a Matplotlib boxplot with m 4 min read Python Plotly - How to add multiple Y-axes? In this article let's see how to add multiple y-axes of different scales in Plotly charts in Python. Currently, Plotly Express does not support multiple Y axes on a single figure. So, we shall use Plotly go. Plotly provides a function called make_subplots() to plot charts with multiple Y - axes. Sy 5 min read How to Plot Multiple DataFrames in Subplots in Python Plotting multiple dataframes in subplots is a powerful technique in data visualization, especially when comparing trends or patterns across different datasets. This approach allows you to display multiple plots within a single figure, making it easier to analyze relationships and differences between 3 min read How to plot a Pandas Dataframe with Matplotlib? We have a Pandas DataFrame and now we want to visualize it using Matplotlib for data visualization to understand trends, patterns and relationships in the data. In this article we will explore different ways to plot a Pandas DataFrame using Matplotlib's various charts. Before we start, ensure you ha 2 min read Pandas - Plot multiple time series DataFrame into a single plot In this article, weâll explore how to plot multiple time series from Pandas DataFrames into a single plot. When working with multiple time series, the most important factor is ensuring that their indexes (usually DateTime indexes) are aligned. Weâll cover two common scenarios:Time series with the sa 3 min read Like