How do I plot a distribution in Seaborn? (With examples)

Seaborn is a library in Python that provides a high-level interface for creating attractive and informative statistical graphics. To plot a distribution in Seaborn, you can use the distplot() function. This function takes in an array of data points to plot and will create a histogram that shows the distribution of the data points. You can also customize the distplot() function with parameters such as bin size, color, and range of values. For example, if you wanted to plot a distribution of ages with a bin size of 5 years and a dark blue color you would use the following code: sns.distplot(ages, bins = 5, color = ‘darkblue’).


You can use the following methods to plot a distribution of values in Python using the data visualization library:

Method 1: Plot Distribution Using Histogram

sns.displot(data)

Method 2: Plot Distribution Using Density Curve

sns.displot(data, kind='kde')

Method 3: Plot Distribution Using Histogram & Density Curve

sns.displot(data, kde=True)

The following examples show how to use each method in practice.

Example 1: Plot Distribution Using Histogram

The following code shows how to plot the distribution of values in a NumPy array using the displot() function in seaborn:

import seaborn as sns
import numpy as np

#make this example reproducible
np.random.seed(1)

#create array of 1000 values that follow a normal distribution with mean of 10
data = np.random.normal(size=1000, loc=10)

#create histogram to visualize distribution of values
sns.displot(data)

The x-axis displays the values in the distribution and the y-axis displays the count of each value.

To change the number of bins used in the histogram, you can specify a number using the bins argument:

import seaborn as sns
import numpy as np

#make this example reproducible
np.random.seed(1)

#create array of 1000 values that follow a normal distribution with mean of 10
data = np.random.normal(size=1000, loc=10)

#create histogram using 10 bins
sns.displot(data, bins=10)

Example 2: Plot Distribution Using Density Curve

import seaborn as sns
import numpy as np

#make this example reproducible
np.random.seed(1)

#create array of 1000 values that follow a normal distribution with mean of 10
data = np.random.normal(size=1000, loc=10)

#create density curve to visualize distribution of values
sns.displot(data, kind='kde')

The x-axis displays the values in the distribution and the y-axis displays the relative frequency of each value.

Note that kind=’kde’ tells seaborn to use kernel density estimation, which produces a smooth curve that summarizes the distribution of values for a variable.

Example 3: Plot Distribution Using Histogram & Density Curve

The following code shows how to plot the distribution of values in a NumPy array using a histogram with a density curve overlaid:

import seaborn as sns
import numpy as np

#make this example reproducible
np.random.seed(1)

#create array of 1000 values that follow a normal distribution with mean of 10
data = np.random.normal(size=1000, loc=10)

#create histogram with density curve overlaid to visualize distribution of values
sns.displot(data, kde=True)

The result is a histogram with a density curve overlaid.

Note: You can find the complete documentation for the seaborn displot() function .

The following tutorials explain how to perform other common tasks using seaborn:

x