Introduction
In this tutorial, we want to create a Heatmap. In order to do this, we use the heatmap() function of Seaborn.
Import Libraries
First, we import the following python modules:
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
Define Data
Let's define our example data. We consider the exam results of a university class. The number of points ranges from 0 to 100. We consider a class with 20 students that took part in five exams.
exam_result = np.random.randint(100, size=(5,20))
print(exam_result)
![](https://www.deeplearningnerds.com/content/images/2023/10/image-139.png)
Plot Heatmap
Now, we would like to visualize the exam results with a heatmap. In order to do this, we use the heatmap() function of Seaborn.
# plotting the heatmap
hm = sns.heatmap(data = exam_result, cmap='Blues',
yticklabels = ('Machine Learning', 'Statistics', 'Computer Science',
'Neural Networks', 'Economics'))
# displaying the heatmap
plt.xlabel("Student Number")
plt.ylabel("Exam")
plt.show()
![](https://www.deeplearningnerds.com/content/images/2023/10/image-141.png)
Conclusion
Congratulations! Now you are one step closer to become an AI Expert. You have seen that it is very easy to create a Heatmap. We can simply use the heatmap() function of Seaborn. Try it yourself!
Also check out our Instagram page. We appreciate your like or comment. Feel free to share this post with your friends.