Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content
No results
  • About AskPython
  • Blog
  • Contact Me
  • Free Online Developer Tools Hub
  • Home
  • Meet the Team
  • Privacy Policy
  • Python
  • Python Course for Beginners Online FREE
  • Python Tutorial – Mega Index
  • Terms and Conditions

🚀 Supercharge your YouTube channel's growth with AI.

Try YTGrowAI Free
  • Home
  • Blog
  • About AskPython
  • Python Course
  • Start Here

HeatMaps in Python – How to Create Heatmaps in Python?

  • Isha BansalIsha Bansal
  • July 30, 2021
  • Python Programming Examples
HeatMaps in Python – How to Create Heatmaps in Python?

Hello there! Today we are going to understand the use of heatmaps in Python and how to create them for different datasets.

What are Heatmaps?

Heatmaps visualize the data in 2-D colored maps making use of color variations like hue, saturation, or luminance. Heatmaps describe relationships between variables in form of colors instead of numbers.

These variables are plotted on both axes. The color changes describe the relationship between two values according to the intensity of the color in a particular block. 

Heatmaps have a lot of applications, some of them are listed below:

  1. Visualizing Business Analytics
  2. Exploring Data Analysis
  3. Exploring Marketing and Sales
  4. Visualizing number of visitors on a website or an application

Industries using Heatmap

Many industries make use of heatmaps nowadays. Some of the industries are:

  • Healthcare
  • Finance
  • Technology
  • Real estate

Plotting Heatmaps in Python

There are multiple ways to plot heatmaps in the python programming language. We will be understanding each method one after another. Let’s list out the methods once for your ease.

  1. Using Seaborn Library
  2. Using pcolormesh() function
  3. Using matplotlib.pyplot library

Method 1 : Using Seaborn Library

To plot a heatmap using the seaborn library, we first need to import all the necessary modules/libraries to our program.

Then we generate a ‘random matrix’ of a particular size and then plot the heatmap with the help of heatmap function and pass the dataset to the function.

# 1. Import Modules
import numpy as np
import seaborn as sns
import matplotlib.pylab as plt
plt.style.use("seaborn")

# 2. Generate a 10x10 random integer matrix
data = np.random.rand(10,10)
print("Our dataset is : ",data)

# 3. Plot the heatmap
plt.figure(figsize=(10,10))
heat_map = sns.heatmap( data, linewidth = 1 , annot = True)
plt.title( "HeatMap using Seaborn Method" )
plt.show()
Heatmap Using Seaborn Heatmaps in Python
Heatmap Using Seaborn

Method 2 : Using pcolormesh Function

To plot a heatmap using the pcolormesh function, we first need to import all the necessary modules/libraries to our code.

We will be plotting the heatmap using various cmaps so we will be making use of subplots in matplotlib. The pcolormesh function of matplotlib needs the dataset and we can specify the color map to plot the heatmap.

import matplotlib.pyplot as plt
import numpy as np

data= np.random.rand(10,10)

plt.subplot(2,2,1)
plt.pcolormesh(data, cmap = 'rainbow')
plt.title('HeatMap Using pcolormesh function')

plt.subplot(2,2,2)
plt.pcolormesh(data, cmap = 'twilight')
plt.title('HeatMap Using pcolormesh function')

plt.subplot(2,2,3)
plt.pcolormesh(data, cmap = 'summer')
plt.title('HeatMap Using pcolormesh function')

plt.subplot(2,2,4)
plt.pcolormesh(data, cmap = 'winter')
plt.title('HeatMap Using pcolormesh function')

plt.tight_layout()

plt.show()
Heatmap Using Pcolormesh Function Heatmaps in Python
Heatmap Using Pcolormesh Function

Method 3 : Using matplotlib.pyplot library

To plot a heatmap using matplotlib.pyplot library, we first need to import all the necessary modules/libraries to our program.

Just like the previous method, we will be plotting the heatmap using various cmaps so we will be making use of subplots in matplotlib. The matplotlib library makes use of the imshow function which needs the dataset and we can specify the color map to plot the heatmap.

import numpy as np
import matplotlib.pyplot as plt

data= np.random.random((10,10))

plt.subplot(2,2,1)
plt.imshow( data, interpolation = 'nearest',cmap="rainbow")
plt.title('HeatMap Using Matplotlib Library')

plt.subplot(2,2,2)
plt.imshow( data, interpolation = 'nearest',cmap="twilight")
plt.title('HeatMap Using Matplotlib Library')

plt.subplot(2,2,3)
plt.imshow( data, interpolation = 'nearest',cmap="summer")
plt.title('HeatMap Using Matplotlib Library')

plt.subplot(2,2,4)
plt.imshow( data, interpolation = 'nearest',cmap="ocean")
plt.title('HeatMap Using Matplotlib Library')

plt.tight_layout()

plt.show()
Heatmap Using Matplotlib Library
Heatmap Using Matplotlib Library

Ending words

Thank you for reading this tutorial! I believe I have covered all the methods to plot heatmaps and now you can try plotting them for real-time data! Stay tuned for more such tutorials!

Isha Bansal
Isha Bansal

Hey there stranger!
Do check out my blogs if you are a keen learner!

Hope you like them!

Articles: 185
Finding an Object in a Python Array – Find the First, Last, and All Occurences of Objects in an Array
Previous Post Finding an Object in a Python Array - Find the First, Last, and All Occurences of Objects in an Array
Next Post Binary Search Using Recursion in Python
Binary Search Using Recursion in Python

Related Posts

How to Calculate Distance Between Two Points in Python

How to Calculate Distance Between Two Points in Python

  • November 26, 2026
CIFAR 10 Dataset: Load and Use in Python

CIFAR 10 Dataset: Load and Use in Python

  • November 24, 2026
Maximum A Posteriori Estimation in Python

Maximum A Posteriori Estimation in Python

  • November 24, 2026

Partner Websites

  • GoLangDocs
  • LinuxForDevices
  • CodeForGeek

Popular Categories

  • Python Programming
  • Python Modules
  • OOPS in Python
  • Python Programming Examples
  • Strings in Python

Hall of Fame

  • Python Programming
  • OOPS in Python
  • Creating Python Modules
  • Args and Kwargs in Python
  • Python Dictionary (Dict) Tutorial
  • Python List – 15 Things You MUST Know
  • Python Set – Things You MUST Know
  • Python String Functions: Methods by Task

Important Links

  • Home
  • Python Course
  • Start Here
  • Blog
  • About AskPython
Latest posts
  • np.linalg.eig: Eigenvalues and Eigenvectors
  • What Does %s Mean in a Python Format String?
  • How to Use np.sin() in NumPy
  • cv2.imread: Load Images with OpenCV
  • pd.read_json: Read JSON Into a DataFrame

Copyright © 2026 - AskPython. All rights reserved.