• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Data Viz with Python and R

Learn to Make Plots in Python and R

  • Home
  • Python Viz
  • Seaborn
  • Altair
  • R Viz
  • ggplot2
  • About
    • Privacy Policy
  • Show Search
Hide Search

How to Make ECDF plot with Seaborn in Python?

datavizpyr · September 16, 2020 ·

ECDF plot, aka, Empirical Cumulative Density Function plot is one of the ways to visualize one or more distributions.

In this post, we will learn how to make ECDF plot using Seaborn in Python. Till recently, we have to make ECDF plot from scratch and there was no out of the box function to make ECDF plot easily in Seaborn. With the Seaborn version 0.11.0 that became available we have function ecdfplot to make ECDF plot.

The ECDF plot has two key advantages. Unlike the histogram or KDE, it directly represents each datapoint. That means there is no bin size or smoothing parameter to consider. Additionally, because the curve is monotonically increasing, it is well-suited for comparing multiple distributions:

With the new Seaborn version we have two functions available to make ECDF plot. We will first use ecdfplot() function in Seaborn to ECDF plot and then also use Seaborn’s displot() function to ECDF plot. Let us load the libraries needed for making ECDF plot.

import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
sns.set_context("talk")
print(sns.__version__)
0.11.0
penguins = sns.load_dataset("penguins")
penguins.head()
species	island	bill_length_mm	bill_depth_mm	flipper_length_mm	body_mass_g	sex
0	Adelie	Torgersen	39.1	18.7	181.0	3750.0	Male
1	Adelie	Torgersen	39.5	17.4	186.0	3800.0	Female
2	Adelie	Torgersen 	40.3	18.0	195.0	3250.0	Female
3	Adelie	Torgersen	NaN	NaN	NaN	NaN	NaN
4	Adelie	Torgersen	36.7	19.3	193.0	3450.0	Female

Simple ECDF plot with Seaborn ecdfplot()

plt.figure(figsize=(8,6))
sns.ecdfplot(penguins, 
             x="flipper_length_mm")
plt.savefig("simple_ecdf_plot_with_ecdfplot_Seaborn.png",
                    format='png',dpi=150)
Simple ECDF plot with ecdfplot()
Simple ECDF plot with ecdfplot()

ECDF plot of multiple distributions

plt.figure(figsize=(8,6))
sns.ecdfplot(penguins, 
             x="flipper_length_mm", 
             hue="island")
plt.savefig("Seaborn_ecdf_plot_with_ecdfplot.png",
                    format='png',dpi=150)
ECDF plot of multiple distributions
ECDF plot of multiple distributions

ECDF plot with Seaborn displot() function

plt.figure(figsize=(10,8))
sns.displot(penguins, 
            x="flipper_length_mm", 
            hue="island",
            kind="ecdf")
plt.savefig("Seaborn_ecdf_plot_with_displot.png",
                    format='png',dpi=150)
ECDF plot with displot()
ECDF plot with displot()

Seaborn version 0.11.0 is filled with tonnes of new features and check out a couple of blog posts to learn about what is new and the new Seaborn functions to make better Data Visualization.

Related posts:

Grouped Boxplot in Python with SeabornGrouped Boxplots in Python with Seaborn Grouped Barplot with SeabornHow To Make Grouped Barplots in Python with Seaborn? Sort bars in barplot descending order with Seaborn PythonHow To Order Bars in Barplot using Seaborn in Python? Bubble plot Seaborn color by variableHow To Make Bubble Plot with Seaborn Scatterplot in Python?

Filed Under: ECDF plot, Python, Seaborn displot(), Seaborn ecdfplot() Tagged With: Python, Seaborn

Primary Sidebar

Tags

Altair barplot Boxplot boxplot python boxplot with jiitered text labels Bubble Plot Color Palette Countplot Density Plot Facet Plot gganimate ggplot2 ggplot2 Boxplot ggplot2 error ggplot boxplot ggridges ggtext element_markdown() Grouped Barplot R heatmap heatmaps Histogram Histograms Horizontal boxplot Python lollipop plot Maps Matplotlib Pandas patchwork pheatmap Pyhon Python R RColorBrewer reorder boxplot ggplot Ridgeline plot Scatter Plot Scatter Plot Altair Seaborn Seaborn Boxplot Stock Price Over Time Stripplot UpSetR Violinplot Violin Plot World Map ggplot2

Buy Me a Coffee

Copyright © 2025 · Daily Dish Pro on Genesis Framework · WordPress · Log in

Go to mobile version