Monday, 15 April 2019

Data Visualization using Distribution Plot (Seaborn Library)

Lets visualize our data with Distribution Plot which is present in Seaborn library. By default distribution plot shows histograms. We will create 150 random numbers and plot them on distribution plot. We can pass various parameters to distplot like color, hist, rug, bins, vertical etc. Lets explore distplot in detail: 

Step 1: Import required libraries

import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
#matplotlib inline

Step 2: Create 150 random numbers

num = np.random.randn(150)
num

Step 3: Explore data using Distribution Plot

Please note that I am not displaying the resulting plots in this post. Please explore it yourself in your Jupyter notebook.

sns.distplot(num)

sns.distplot(num, color='red')

label_dist = pd.Series(num, name="variable x")  #convert random numbers into pandas series

sns.distplot(label_dist)

sns.distplot(label_dist, vertical=True)  #vertical histogram

sns.distplot(label_dist, hist=False)  #remove histogram from distribution plot

sns.distplot(label_dist, hist=False, rug=True)  #specify rug parameter

sns.distplot(label_dist, bins=20)  #specify number of bins you want to create

No comments:

Post a Comment