作者:能豆子2014 | 来源:互联网 | 2022-12-29 19:39
如何设置彩条标签的字体大小?
ax=sns.heatmap(table, vmin=60, vmax=100, xticklabels=[4,8,16,32,64,128],yticklabels=[2,4,6,8], cmap="PuBu",linewidths=.0,
annot=True,cbar_kws={'label': 'Accuracy %'}
![在此输入图像描述](https://img.php1.cn/3cd4a/1eebe/cd5/8be1ccb5166feb93.webp)
1> ImportanceOf..:
不幸的是,seaborn无法访问它创建的对象.因此,需要绕道而行,使用颜色条是当前图形中的轴并且它是最后创建的轴,因此
ax = sns.heatmap(...)
cbar_axes = ax.figure.axes[-1]
对于这个轴,我们可以通过使用其set_size
方法获取ylabel来设置fontsize .
例如,将fontsize设置为20个点:
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()
![在此输入图像描述](https://img.php1.cn/3cd4a/1eebe/cd5/70be2ca197098d98.webp)
注意,当然可以通过via实现相同的目的
ax = sns.heatmap(data)
ax.figure.axes[-1].set_ylabel('Accuracy %', size=20)
没有关键字参数传递.