How do I add a title to Seaborn Heatmap? How do I add a title to Seaborn Heatmap? pandas pandas

How do I add a title to Seaborn Heatmap?


heatmap is an axes-level function, so you should be able to use just plt.title or ax.set_title:

%matplotlib inlineimport numpy as npimport osimport seaborn as snsimport matplotlib.pyplot as pltdata = np.random.randn(10,12)ax = plt.axes()sns.heatmap(data, ax = ax)ax.set_title('lalala')plt.show()

enter image description here


To give title for seaborn heatmap use

plt.title("Enter your title", fontsize =20)

or ax.set(title = "Enter your title")

import seaborn as sns # for data visualizationimport matplotlib.pyplot as plt # for data visualizationflight = sns.load_dataset('flights') # load flights datset from GitHub seaborn repository# reshape flights dataeset in proper format to create seaborn heatmapflights_df = flight.pivot('month', 'year', 'passengers') ax = sns.heatmap(flights_df) # create seaborn heatmapplt.title('Heatmap of Flighr Dataset', fontsize = 20) # title with fontsize 20plt.xlabel('Years', fontsize = 15) # x-axis label with fontsize 15plt.ylabel('Monthes', fontsize = 15) # y-axis label with fontsize 15plt.show()

Output >>>

enter image description here


Alternatively sns.plt.suptitle('lalala') would work if you have multiple subplots.