Seaborn heatmap - colorbar label font size
You could also explicitly pass in the axes objects into heatmap
and modify them directly:
grid_spec = {"width_ratios": (.9, .05)}
f, (ax, cbar_ax) = plt.subplots(1,2, gridspec_kw=grid_spec)
sns.heatmap(data, ax=ax, cbar_ax=cbar_ax, cbar_kws={'label': 'Accuracy %'})
cbar_ax.yaxis.label.set_size(20)
Unfortunately seaborn does not give access to the objects it creates. So one needs to take the detour, using the fact that the colorbar is an axes in the current figure and that it is the last one created, hence
ax = sns.heatmap(...)
cbar_axes = ax.figure.axes[-1]
For this axes, we may set the fontsize by getting the ylabel using its set_size
method.
Example, setting the fontsize to 20 points:
import matplotlib.pyplot as plt
import numpy as np; np.random.seed(0)
import seaborn as sns
data = np.random.rand(10, 12)*100
ax = sns.heatmap(data, cbar_kws={'label': 'Accuracy %'})
ax.figure.axes[-1].yaxis.label.set_size(20)
plt.show()
Note that the same can of course be achieved by via
ax = sns.heatmap(data)
ax.figure.axes[-1].set_ylabel('Accuracy %', size=20)
without the keyword argument passing.