Seaborn 101

Seaborn is a Python-based data visualization library, which is based on matplotlib (https://seaborn.pydata.org/) . I would like to share some guidance/code to get started with drawing plots using this library! I will be using the dataset ‘flights’ from Seaborn (https://github.com/mwaskom/seaborn-data) to highlight an example.

1. Installation of Seaborn

#if you want to install via pip 
pip install seaborn 
#if you want to install via conda
conda install seaborn 

2. Import Seaborn on Python

import seaborn as sns 

3. Load and Check the Data

#load dataframe 'flights' from Seaborn 
flights_df = sns.load_dataset('flights')

#view flights_df
flights_df

4. Sample Plots to Visualize the Data

Bar Plot

sns.catplot(x='year', y='passengers', data=flights_df, kind='bar', hue='month')

Scatter Plots

As shown below, ‘hue’ allows to specify the column in the dataframe that should be used for colour encoding.

#without hue
sns.catplot(x='year', y='passengers', data=flights_df)
#with hue
sns.catplot(x='year', y='passengers', data=flights_df, hue='month')

Violin Plot

sns.catplot(x='month', y='passengers', data=flights_df, kind='violin')

Author