How to Create a Heat Map in Seaborn

2021-01-28

Intro

A heat map is a matrix plot type. In general, heat map compare pairs of values with some measurement between the pairs. One of the most common uses for a heat map is to display correlation or how correlated pairs of variables are two each other. This is a common task in machine learning and data science. In this article, we will see how to create a Heat Map in the Seaborn Library.

Creating the Heat Map

To create a heat map, we use the heatmap method. Unlike other plots, we need to reformat the data before passing it to Seaborn. A heat map plots correlations, so we can use the pandas method corr to create a correlation matrix. Then, we plot this matrix.

import seaborn as sns 

dataset = sns.load_dataset('tips') 
  
## Use pandas's corr matrix function
corrMatrix = dataset.corr() 
  
sns.heatmap(corrMatrix) 
GoTea - KoalaTea