Data Visualization using Heatmap (Seaborn Library)

Home » News » Data Visualization using Heatmap (Seaborn Library)
Lets visualize our data with Heatmap which is present in Seaborn library. Heatmap is full of colors. Darker the color, higher is the value and vice versa. Values closer to 1 represent higher values and values closer to 0 represent lower values. We will use Flights dataset and analyze it through heatmap. We can pass various parameters to heatmap like annot, fmt, vmin, vmax, cbar, cmap, linewidths, center etc. Lets explore heatmap in detail: 

Step 1: Import required libraries

import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
#matplotlib inline

Step 2: Load Flights datasets


flights = sns.load_dataset(‘flights')
flights.head()
flights.tail()


Step 3: Explore data using Heat Map

Please note that I am not displaying the resulting maps in this post. Please explore it yourself in your Jupyter notebook.


Before exploring Flights dataset with Heatmap, lets first analyze some random numbers using Heatmap:


numbers = np.random.randn(12, 15)
numbers


sns.heatmap(numbers)


sns.heatmap(numbers, annot=True)  #to show actual values in the heatmap


sns.heatmap(numbers, annot=True, vmin=0, vmax=2)  #to change the key value of heatmap, by default key varies from 0 and 1.


sns.heatmap(flights, cbar=False)  #to hide the color bar


Now, lets jump to our Flights dataset. Lets pivot this dataset so that we have “year” on x-axis and “month” on y-axis.


flights = flights.pivot(‘month', ‘year', ‘passengers')
flights


sns.heatmap(flights)


sns.heatmap(flights, annot=True)


sns.heatmap(flights, annot=True, fmt='d')  #format the annotation to contain only digits


sns.heatmap(flights, annot=True, fmt='d', linewidths=0.9)  #add linewidth to heatmap


sns.heatmap(flights, annot=True, fmt='d', linewidths=0.9, cmap='RdBu')  #add color map to heatmap to change the color


sns.heatmap(flights, annot=True, fmt='d', linewidths=0.9, cmap='summer')


sns.heatmap(flights, annot=True, fmt='d', linewidths=0.9, cmap='winter_r')


sns.heatmap(flights, annot=True, fmt='d', linewidths=0.9, cmap='coolwarm')


sns.heatmap(flights, annot=True, fmt='d', center=flights.loc[‘June', 1954])  #center color theme to a particular cell

Leave a Reply

Your email address will not be published. Required fields are marked *

New Providers
Binolla

The Broker
More then 2 million businesses
See Top 10 Broker

gamehag

Online game
More then 2 million businesses
See Top 10 Free Online Games

New Games
Lies of P

$59.99 Standard Edition
28% Save Discounts
See Top 10 Provider Games

COCOON

$24.99 Standard Edition
28% Save Discounts
See Top 10 Provider Games

New Offers
Commission up to $1850 for active user of affiliate program By Exness

Top Points © Copyright 2023 | By Topoin.com Media LLC.
Topoin.info is a site for reviewing the best and most trusted products, bonus, offers, business service providers and companies of all time.

Discover more from Top Points

Subscribe now to keep reading and get access to the full archive.

Continue reading