Data Visualization using FacetGrid (Seaborn Library)

Home » News » Data Visualization using FacetGrid (Seaborn Library)
Lets visualize our data with Facet Grid which is present in Seaborn library. Facet Grid can be used with Histogram, Scatter Plot, Regression Plot, Box Plot etc. 


We can pass various parameters to FacetGrid like row, col, col_order, hue, palette, height, aspect etc. To add legend to Facet Grid, you can use add_legend() function. 


Lets explore Facet Grid with Tips dataset. 

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 datasets

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

Step 3: Explore data using Facet Grid


Facet Grid with Histogram


x = sns.FacetGrid(tips, row='smoker', col='time')
x = x.map(plt.hist, ‘total_bill')


x = sns.FacetGrid(tips, row='smoker', col='time')
x = x.map(plt.hist, ‘total_bill', bins=15, color='green')


Facet Grid with Scatter Plot


x = sns.FacetGrid(tips, row='smoker', col='time')
x = x.map(plt.scatter, ‘total_bill', ‘tip')

Facet Grid with Regression Plot


x = sns.FacetGrid(tips, row='smoker', col='time', height=6, aspect=0.7)
x = x.map(sns.regplot, ‘total_bill', ‘tip')


x = sns.FacetGrid(tips, col='time', hue='smoker', palette='husl')
x = x.map(sns.regplot, ‘total_bill', ‘tip')


x = sns.FacetGrid(tips, col='time', hue='smoker')
x = x.map(sns.regplot, ‘total_bill', ‘tip').add_legend()

Facet Grid with Box Plot


x = sns.FacetGrid(tips, col='day', height=10, aspect=0.2)
x = x.map(sns.boxplot, ‘time', ‘total_bill')


x = sns.FacetGrid(tips, col='day', height=10, aspect=0.2, col_order=[‘Sat', ‘Sun', ‘Thur', ‘Fri'])
x = x.map(sns.boxplot, ‘time', ‘total_bill', color='red')


You can download my Jupyter notebook from here. I recommend to also try above code with Iris dataset.

Leave a Reply

Your email address will not be published. Required fields are marked *

New Providers
Binolla

The Broker
More then 2 million businesses
See Top 10 Broker

gamehag

Online game
More then 2 million businesses
See Top 10 Free Online Games

New Games
Lies of P

$59.99 Standard Edition
28% Save Discounts
See Top 10 Provider Games

COCOON

$24.99 Standard Edition
28% Save Discounts
See Top 10 Provider Games

New Offers
Commission up to $1850 for active user of affiliate program By Exness

Top Points © Copyright 2023 | By Topoin.com Media LLC.
Topoin.info is a site for reviewing the best and most trusted products, bonus, offers, business service providers and companies of all time.

Discover more from Top Points

Subscribe now to keep reading and get access to the full archive.

Continue reading