- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to animate a Seaborn heatmap or correlation matrix(Matplotlib)?
To animate a Seaborn heatmap or correlation matrix, we can take the following steps −
- Set the figure size and adjust the padding between and around the subplots.
- Create a new figure or activate an existing figure.
- Make a dimension tuple.
- Make a Seaborn heatmap.
- Create an init() method for the first heatmap.
- Use FuncAnimation() class to make an animation by repeatedly calling a function animate that will create a random dataset and create a heatmap.
- To display the figure, use show() method.
Example
import numpy as np import seaborn as sns import matplotlib.pyplot as plt from matplotlib import animation plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig = plt.figure() dimension = (5, 5) data = np.random.rand(dimension[0], dimension[1]) sns.heatmap(data, vmax=.8) def init(): sns.heatmap(np.zeros(dimension), vmax=.8, cbar=False) def animate(i): data = np.random.rand(dimension[0], dimension[1]) sns.heatmap(data, vmax=.8, cbar=False) anim = animation.FuncAnimation(fig, animate, init_func=init, frames=20, repeat=False) plt.show()
Output
- Related Articles
- How to make a heatmap square in Seaborn FacetGrid using Matplotlib?
- How to remove X or Y labels from a Seaborn heatmap?
- Auto adjust font size in Seaborn heatmap using Matplotlib
- How to hide the colorbar of a Seaborn heatmap?
- Set Max value for color bar on Seaborn heatmap using Matplotlib
- How to annotate each cell of a heatmap in Seaborn?
- How to make custom grid lines in Seaborn heatmap?
- How to understand Seaborn's heatmap annotation format?
- How to remove the axis tick marks on a Seaborn heatmap?
- Adding units to heatmap annotation in Seaborn
- How to convert a correlation matrix into a logical matrix based on correlation coefficient in R?
- How to plot a non-square Seaborn jointplot or JointGrid? (Matplotlib)
- How to annotate a heatmap with text in Matplotlib?
- How to animate a pcolormesh in Matplotlib?
- How to animate a line plot in Matplotlib?

Advertisements