Data Visualization Using Seaborn- Python Package


Seaborn is one of the Python package used for data visualization. It is a data visualization package similar to matplotlib yet better than it. One major drawback of Matplotlib is that customization is not easy in matplotlib. Although it has a number of interfaces to make things easy to work out. Another drawback of matplotlib is, it doesn’t serve well when dealing with pandas and dataframes. It actually works on dataframes, thus, making work easier.

Data Visualization Using Seaborn- Python Package
Python Package- Seaborn

Setting the Environment

In order to install the python package, type the following in the command prompt

pip install seaborn

Some dependencies of this library are Matplotlib, Numpy, Pandas, SciPy, statsmodel. After installing the above library make sure to have these libraries installed.

Some Important Plots in Seaborn are:


# Stripplot using inbuilt data-set given in seaborn 
# import the required module 
import matplotlib.pyplot as plt 
import seaborn as sns 
#set the style of background of plot 
sns.set(style ="whitegrid")  
# load the inbuilt data-set 
iris_dataset = sns.load_dataset('iris');  
# plotting strip plot with seaborn and deciding the attributes of dataset
plot = sns.stripplot(x = 'species', y = 'sepal_length', data = iris_dataset);  
#title of the plot
#display the plot 
Data Visualization Using Seaborn- Python Package


  • .set() sets theme/background of the plot. Whitegrid denotes white background while Darkgrid denotes dark/black background.
  • .load_dataset() loads the inbuilt dataset in the package in a dataframe.
  • .stripplot() decides which attribute is to be taken on the x-axis and y-axis respectively.
  • .title() provides the plot with a suitable title.


#importing required libraries
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
#choosing background/theme
#loading the inbuilt dataset
f = sns.load_dataset("flights")
#plotting the data 
sns.relplot(x="passengers", y="month", data=f);
Data Visualization Using Seaborn- Python Package

Various types of relplots are: Scatterplots, Lineplots. Using “kind” attribute these plots can be choosen inside relplots. x-axis and y-axis are specified in the parameters. .title() provides suitable title to the plot. Here, inbuilt dataset in the package is used.

Other important plots are:

  1. For categorical data:
    • swarmplot()
    • boxplot()
    • violinplot()
    • barplot(), etc.
  2. For visualizing distribution of datasets
    • distplot()
    • rugplot()
    • hexbin()
    • jointplot()
Data Visualization Using Seaborn- Python Package
Some Basic Plots

FAQ’s :

1. What do you mean by colorpalettes?

Colorpalettes are combination/collection of different colors. Depending on different colors and their intensities, different data can be plotted and analyzed easily.

2. Difference between Seaborn and Matplotlib.

Seaborn is a python package based on Matplotlib. When data is read into dataframes, seaborn makes it easy to analyze the data in comparison to matplotlib. Also, customization is easy in seaborn comparative to matplotlib.

3. List the dependencies of Seaborn.

Four major dependencies of Seaborn are: NumPy, Matplotlib, Pandas and SciPy