How to Make ECDF Plot with Seaborn in Python?
Last Updated :
27 Jan, 2023
Prerequisites: Seaborn
In this article, we are going to make the ECDF plot with Seaborn Library.
ECDF Plot
- ECDF stands for Empirical Commutative Distribution. It is more likely to use instead of the histogram for visualizing the data because the ECDF plot visualizes each and every data point of the dataset directly, which makes it easy for the user to interact with the plot.
- This plot contains more information because it has no bin size setting, which means it doesn't have any smoothing parameters.
- Since its curves are monotonically increasing, so it is well suited for comparing multiple distributions at the same time.
- In an ECDF plot, the x-axis corresponds to the range of values for the variable whereas the y-axis corresponds to the proportion of data points that are less than or equal to the corresponding value of the x-axis.
- We can make the ECDF plot directly by using ecdfplot() function, or we can also make the plot by using displot() function with the new Seaborn version.
Installation:
To install the Seaborn library, write the following command in your command prompt.
pip install seaborn
This ECDF plot and displot() function is available only in the new version of Seaborn that is version 0.11.0 or above. If already install Seaborn upgrade it by writing the following command.
pip install seaborn==0.11.0
For a better understanding of the ECDF plot. Let's plot and do some examples using the datasets.
Step-by-Step Approach:
- Import the seaborn library.
- Create or load the dataset from the seaborn library.
- Select the column for which you are plotting the ECDF plot.
- For plotting the ECDF plot there are two ways are as follows:
- The first way is to use ecdfplot() function to directly plot the ECDF plot and in the function pass you data and column name on which you are plotting.
Syntax:
seaborn.ecdfplot(data='dataframe',x='column_name',y='column_name', hue='color_column')
- The second way is to use displot() function and pass your data and column on which you are making the plot and pass the parameter of displot kind='ecdf'.
Syntax:
seaborn.displot(data='dataframe', x='column_name',y='column_name' kind='type_of_plot',hue='color_column', palette='color'
The below table shows the list of parameters used in this article.
Parameter | Description |
---|
data | Data frame or numpy.ndarray |
x | Key vectors in data or column name on which plot is made. |
y | Key vectors in data or column name on which plot is made. |
hue | To determine the color of the plot variable. |
palette |
This parameter is used to choose color when mapping the hue.
It can be string, list, dict.
|
kind | It is the parameter of displot(), used to give the kind of plot we want. |
Method 1: Using ecdfplot() method
In this method, we are using 'exercise' data provided by seaborn.
Python
# importing library
import seaborn as sns
# loading exercise dataset provided by seaborn
excr = sns.load_dataset('exercise')
# printing the dataset
print(excr)
Output:

Example 1: Making ECDF plot by using exercise dataset provided by seaborn.
Python
# importing libraries
import seaborn as sns
import matplotlib.pyplot as plt
# loading exercise dataset provided by seaborn
excr = sns.load_dataset('exercise')
# making ECDF plot
sns.ecdfplot(data=excr,x='pulse')
# visualizing the plot using matplotlib.pyplot
# show() function
plt.show()
Output:

Example 2: Making ECDF plot by interchanging the plot axis.
Python
# importing libraries
import seaborn as sns
import matplotlib.pyplot as plt
# loading exercise dataset provided by seaborn
excr = sns.load_dataset('exercise')
# making ECDF plot
sns.ecdfplot(data=excr,y='pulse')
# visualizing the plot using matplotlib.pyplot
# show() function
plt.show()
Output:

Example 3: Making ECDF plot when we have multiple distributions.
Python
# importing libraries
import seaborn as sns
import matplotlib.pyplot as plt
# loading exercise dataset provided by seaborn
excr = sns.load_dataset('exercise')
# making ECDF plot when we have multiple
# distributions
sns.ecdfplot(data=excr, x='pulse', hue='kind')
# visualizing the plot using matplotlib.pyplot
# show() function
plt.show()
Output:

The above plot shows the distribution of pulse rate of the peoples with respect to the kind i.e, rest, walking, running.
Method 2: Using displot() method
In this method, we are using 'diamonds' data provided by seaborn.
Python
# importing library
import seaborn as sns
# loading diamonds dataset provided by seaborn
diam = sns.load_dataset('diamonds')
# printing the dataset
print(diam)
Output:

Example 1: Plotting ECDF plot using displot() on penguins dataset provided by seaborn.
Python
# importing libraries
import seaborn as sns
import matplotlib.pyplot as plt
# loading diamonds dataset provided by seaborn
diam = sns.load_dataset('diamonds')
# making ECDF plot using displot() on depth
# of the diamonds
sns.displot(data=diam,x='depth',kind='ecdf')
# visualizing the plot using matplotlib.pyplot
# show() function
plt.show()
Output:

Example 2: Plotting ECDF plot using displot() when we have multiple distributions with default setting.
Python
# importing libraries
import seaborn as sns
import matplotlib.pyplot as plt
# loading diamonds dataset provided by seaborn
diam = sns.load_dataset('diamonds')
# making ECDF plot using displot() on depth
# of the diamond on the basis of cut
sns.displot(data=diam,x='depth',kind='ecdf',hue='cut')
# visualizing the plot using matplotlib.pyplot
# show() function
plt.show()
Output:

The above plot shows the depth of the diamonds on the basis of their cut.
Example 3: Making ECDF plot using displot() by setting up the color.
Python
# importing libraries
import seaborn as sns
import matplotlib.pyplot as plt
# loading diamonds dataset provided by seaborn
diam = sns.load_dataset('diamonds')
# making ECDF plot using displot() on table
# column on the basis of cut of diamond
# setting up the color of plot by setting
# up the palette to icefire_r
sns.displot(data=diam,x='table',kind='ecdf',hue='cut',palette='icefire_r')
# visualizing the plot using matplotlib.pyplot
# show() function
plt.show()
Output:

We can set the palette to Accent_r, magma_r, plasma, plasma_r, etc, according to our choice, it has many other options available.
Similar Reads
Python Tutorial | Learn Python Programming Language Python Tutorial â Python is one of the most popular programming languages. Itâs simple to use, packed with features and supported by a wide range of libraries and frameworks. Its clean syntax makes it beginner-friendly.Python is:A high-level language, used in web development, data science, automatio
10 min read
Python Interview Questions and Answers Python is the most used language in top companies such as Intel, IBM, NASA, Pixar, Netflix, Facebook, JP Morgan Chase, Spotify and many more because of its simplicity and powerful libraries. To crack their Online Assessment and Interview Rounds as a Python developer, we need to master important Pyth
15+ min read
Non-linear Components In electrical circuits, Non-linear Components are electronic devices that need an external power source to operate actively. Non-Linear Components are those that are changed with respect to the voltage and current. Elements that do not follow ohm's law are called Non-linear Components. Non-linear Co
11 min read
Python OOPs Concepts Object Oriented Programming is a fundamental concept in Python, empowering developers to build modular, maintainable, and scalable applications. By understanding the core OOP principles (classes, objects, inheritance, encapsulation, polymorphism, and abstraction), programmers can leverage the full p
11 min read
Python Projects - Beginner to Advanced Python is one of the most popular programming languages due to its simplicity, versatility, and supportive community. Whether youâre a beginner eager to learn the basics or an experienced programmer looking to challenge your skills, there are countless Python projects to help you grow.Hereâs a list
10 min read
Python Exercise with Practice Questions and Solutions Python Exercise for Beginner: Practice makes perfect in everything, and this is especially true when learning Python. If you're a beginner, regularly practicing Python exercises will build your confidence and sharpen your skills. To help you improve, try these Python exercises with solutions to test
9 min read
Python Programs Practice with Python program examples is always a good choice to scale up your logical understanding and programming skills and this article will provide you with the best sets of Python code examples.The below Python section contains a wide collection of Python programming examples. These Python co
11 min read
Spring Boot Tutorial Spring Boot is a Java framework that makes it easier to create and run Java applications. It simplifies the configuration and setup process, allowing developers to focus more on writing code for their applications. This Spring Boot Tutorial is a comprehensive guide that covers both basic and advance
10 min read
Class Diagram | Unified Modeling Language (UML) A UML class diagram is a visual tool that represents the structure of a system by showing its classes, attributes, methods, and the relationships between them. It helps everyone involved in a projectâlike developers and designersâunderstand how the system is organized and how its components interact
12 min read
Python Data Types Python Data types are the classification or categorization of data items. It represents the kind of value that tells what operations can be performed on a particular data. Since everything is an object in Python programming, Python data types are classes and variables are instances (objects) of thes
9 min read