Visualize Distributions Using Seaborn
Seaborn is a powerful Python visualization library built on top of Matplotlib. It simplifies the process of creating attractive and informative statistical graphics, including plots for visualizing data distributions.
Installing Seaborn
If you already have Python and pip installed, you can install Seaborn by running:
pip install seaborn
If you are working in Jupyter Notebook, use:
!pip install seaborn
Creating Distribution Plots (Displots)
Importing Matplotlib
To use Matplotlib for plotting, import the pyplot module with the following command:
Import Seaborn
Basic Displot Example (Histogram)
import matplotlib.pyplot as plt
import seaborn as sns
sns.displot([0, 1, 2, 3, 4, 5])
plt.show()
Output:
Displot with KDE Curve (Without Histogram)
To plot only the KDE (Kernel Density Estimate) curve without the histogram, use the kind="kde" argument:
import matplotlib.pyplot as plt
import seaborn as sns
sns.displot([0, 1, 2, 3, 4, 5], kind="kde")
plt.show()
Output:
Note:
In this tutorial, we’ll use:
sns.displot(arr, kind="kde")
to visualize random distributions.