We use a displot (also known as a distribution plot) to represent data in histogram form. It is a univariant set of collected data, which means the data distribution of one variable will be shown against another variable.
In Python, we use the Seaborn library with Matplotlib
for data visualization. It provides an interface that allows users to present data in various descriptive and eye-catching graphics in statistical form. Seaborn will enable us to deliver data using the types below:
Now let’s dive deeper.
In Seaborn, we use the seaborn.displot()
function to display one data variable's distribution against the other variable as density distribution.
The function seaborn.displot()
takes data variable and color as arguments and returns data in distribution form.
# import librariesimport numpy as npimport seaborn as snsimport matplotlib.pyplot as plt# code to generate random numbersdata = np.random.randn(500)# plot distplotsns.displot(data, color="red")plt.title("Data Distribution")plt.savefig('output/graph.png')
numpy
, seaborn
, and matplotlib
libraries in the program.np.random.randn(500)
to generate an array of random numbers. In this line, it will create 500 random values.seab.displot(data)
function to generate a distribution plot. We use the seab.displot(data)
function to plot a distribution plot of data in the form of a histogram.plt.title()
function to set the graph title to "Data Distribution"
.plt.savefig()
function to save the graph generated above as graph.png
in the output directory.