How To Plot Heatmap in Python
A Heatmap is a statistical representation that helps to represent the importance of the features in form of colors. In this article, we learn to plot a heatmap in Python. They are different methods to plot heatmap
Method 1: Using Seaborn Library
heatmap() function in seaborn help to plot heatmap
import numpy as np import seaborn as sns import matplotlib.pylab as plt df = np.random.rand( 5 , 5) ax = sns.heatmap( df , linewidth = 0.25 , annot = True) plt.title( "Heat Map" ) plt.show()
Output
Method 2: Using matplotlib.pyplot library
imshow() function in matplotlib.pyplot help to plot heatmap
import numpy as np import matplotlib.pyplot as plt data = np.random.random((6 , 6)) plt.imshow( data, interpolation = 'nearest') plt.title( "Heat Map" ) plt.show()
Output
Method 3: Using matplotlib.pyplot library – pcolormesh() function
The pcolormesh() function in the pyplot module of the matplotlib library is used to create a pseudo-color map with an irregular rectangular grid.
Syntax
matplotlib.pyplot.pcolormesh(*args, alpha=None, norm=None, cmap=None, vmin=None, vmax=None, shading=’flat’, antialiased=False, data=None, **kwargs)
Sample Code
import matplotlib.pyplot as plt import numpy as np df = np.random.rand(5, 5) plt.pcolormesh(df, cmap = 'autumn') plt.title('Heat Map') plt.show()
Output
Also, refer
Chess Board Using MatPlotLib Python
Leave a Reply