Sunday, 14 April 2019

Data Visualization using Strip Plot (Seaborn Library)

Lets visualize our data with Strip Plot which is present in Seaborn library. We will use Tips dataset. We can pass various parameters to stripplot like palette, color, jitter, linewidth, hue, dodge, marker, size, order, edgecolor, alpha etc. Lets explore stripplot 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: Load Tips dataset

tips=sns.load_dataset('tips')
tips.head()

Step 3: Explore data using Strip Plot

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

#Visualizing one variable using Strip Plot

sns.stripplot(x=tips['tip'])

sns.stripplot(x=tips['total_bill'])

sns.stripplot(x='total_bill', data=tips)

sns.stripplot(x='total_bill', data=tips, color='green')

#Visualizing two variables using Strip Plot

sns.stripplot(x='day', y='total_bill', data=tips)

sns.stripplot(x='total_bill', y='day', data=tips)

sns.stripplot(x='day', y='total_bill', data=tips, jitter=False)

sns.stripplot(x='day', y='total_bill', data=tips, jitter=0.3)

sns.stripplot(x='day', y='total_bill', data=tips, jitter=0.3, linewidth=1.2)

sns.stripplot(x='day', y='total_bill', data=tips, hue='sex')

sns.stripplot(x='day', y='total_bill', data=tips, hue='sex', jitter=False)

sns.stripplot(x='day', y='total_bill', data=tips, hue='sex', dodge=True)

sns.stripplot(x='day', y='total_bill', data=tips, hue='sex', dodge=True, palette='winter_r')

sns.stripplot(x='day', y='total_bill', data=tips, hue='sex', dodge=True, palette='winter_r', order=['Sat', 'Sun', 'Thur', 'Fri'])

sns.stripplot(x='day', y='total_bill', data=tips, hue='sex', dodge=True, marker='D')

sns.stripplot(x='day', y='total_bill', data=tips, hue='sex', dodge=True, marker='D', size=10)

sns.stripplot(x='day', y='total_bill', data=tips, hue='sex', dodge=True, marker='D', size=10, edgecolor='gray', alpha=0.3)

#Combining Strip Plot and Box Plot

sns.stripplot(x='day', y='total_bill', data=tips)
sns.boxplot(x='day', y='total_bill', data=tips)

sns.stripplot(x='day', y='total_bill', data=tips, jitter=False, palette='husl', color=0.1)
sns.boxplot(x='day', y='total_bill', data=tips)

#Combining Strip Plot and Violin Plot

sns.stripplot(x='day', y='total_bill', data=tips, jitter=False, palette='husl', color=0.1)
sns.violinplot(x='day', y='total_bill', data=tips)

No comments:

Post a Comment