Answer a question

I wanted to change the font size for a heatmap colorbar.

The following is my code:

import seaborn as sns
import matplotlib.pyplot as plt
from numpy import arange
x = arange(25).reshape(5, 5)
cmap = sns.diverging_palette(220, 20, sep=20, as_cmap=True)
ax = sns.heatmap(x, cmap=cmap)
plt.show()

I was able to change the tick labels with plt.tick_params(axis='both', labelsize=20). However, the colorbar font size does not change. Is there a way to do that?

enter image description here

Answers

You can change the font scale with the seaborn.set() method setting the font_scale param to the scale you want, see more in seaborn documentation.

For example, your plot with scale 3:

import seaborn as sns
import matplotlib.pyplot as plt
from numpy import arange
# here set the scale by 3
sns.set(font_scale=3)
x = arange(25).reshape(5, 5)
cmap = sns.diverging_palette(220, 20, sep=20, as_cmap=True)
ax = sns.heatmap(x, cmap=cmap)
plt.show()

plot with big font scale

Logo

Python社区为您提供最前沿的新闻资讯和知识内容

更多推荐