Search
[Python] Give a title to the colorbar with Seaborn heatmap
- M.R

- Oct 16, 2021
- 1 min read
Overview
When you create a heatmap with seaborn, you also want to give a title to the color bar.
This time, I will introduce how to do it.
Method
Do as follows.
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
x=np.random.randint(0, 10, (8, 8))
fig, ax=plt.subplots()
ax=sns.heatmap(x)
ax.collections[0].colorbar.set_label('Colorbar Label')
plt.show()
Properties can be changed with the argument of set_label ().
//omit
ax.collections[0].colorbar.set_label('Colorbar Label', labelpad=20, fontsize=14)
//omit






Comments