How to Create a HeatMap with Matplotlib

2020-12-27

Intro

A heatmap helps you compares pairs of varaibles and their respective intensity. They are commonly used to show correlations bettwen paris of variables (or predictors) in a model. In this article, we will see how to create a Heatmap with MatPlotLib.

Creating the Heatmap

To create a Heatmap, we first need a correlation matrix. We can easily get on using the pandas libraries dataframe and corr function. Grab the csv from this url to follow allong: https://archive.ics.uci.edu/ml/datasets/Wine+Quality.

Once we have a correlation matrix, we can use pyplot's imshow function with the cmap option set to hot. We also call colorbar to have a legend on the side of our graph

import matplotlib.pyplot as plt
import pandas as pd

wine = pd.read_csv('winequality.csv', 
						   delimiter=';')

corr = wine.corr()

plt.imshow(corr, cmap = 'hot')
plt.colorbar()

plt.show()
GoTea - KoalaTea