Heatmap using Matplotlib and seaborn – Data Visualization using Python

A heatmap is a graphical representation of data where the individual values contained in a matrix are represented as colors. There are many different color schemes that can be used to illustrate the heatmap, with perceptual advantages and disadvantages for each. Rainbow colormaps are often used.

matplotlib as we as  seaborn can be used for creating heatmap. creating heatmap is bit difficult using matplotlib. Here is one example of using matplotlib for creating heatmap.

output is as below

Here is similar heatmap using searborn

Here is the output

As you can see, heatmap seems more refined and user friendly using seaborn than matplotlib. seaborn is not a replacement of matplotlib, its built on top of matplotlib only and these can be used together

Here is more complex heatmap

output is as below

Using desired color code:

Parameter cmap is used to control the color code. You can use any of following parameters to get desired colors.

BuGn_r,Blues,BrBG,cubehelix,sns.cubehelix_palette(8),sns.light_palette(“green”),sns.light_palette(“navy”, reverse=False),YlGnBu

Also note that, you can define your own color scheme as well, please refer to official documentation for this here.

 

One Reply to “Heatmap using Matplotlib and seaborn – Data Visualization using Python”

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.