Matplotlib 如何增加Seaborn heatmap中注释的单元格大小

Matplotlib 如何增加Seaborn heatmap中注释的单元格大小,matplotlib,data-visualization,heatmap,seaborn,Matplotlib,Data Visualization,Heatmap,Seaborn,我想用min=0和max=15075(共享)绘制66x66混淆矩阵。因为我想对单元格进行注释,所以我使用了annot=True。但我似乎无法适应单元格中的值,即使尝试了其他堆栈溢出帖子中建议的方法,如,和。这是我当前的代码: from sklearn.metrics import confusion_matrix conf_mat = confusion_matrix(y_test, y_pred) # please load the data from the pastebin [link a

我想用
min=0
max=15075
(共享)绘制
66x66
混淆矩阵。因为我想对单元格进行注释,所以我使用了
annot=True
。但我似乎无法适应单元格中的值,即使尝试了其他堆栈溢出帖子中建议的方法,如,和。这是我当前的代码:

from sklearn.metrics import confusion_matrix
conf_mat = confusion_matrix(y_test, y_pred) # please load the data from the pastebin [link above][1]

# get the tick label font size
fontsize_pt = 10 # plt.rcParams['ytick.labelsize'] does not return a numeric value like suggested [here][2], so I set it to '10'
dpi = 72.27

# comput the matrix height in points and inches
matrix_height_pt = fontsize_pt * conf_mat.shape[0]
matrix_height_in = matrix_height_pt / dpi

# compute the required figure height 
top_margin = 0.04
bottom_margin = 0.04
figure_height = matrix_height_in / (1 - top_margin - bottom_margin)

# build the figure instance with the desired height
fig, ax = plt.subplots(figsize=(20, figure_height),
                       gridspec_kw=dict(top=(1-top_margin), bottom=bottom_margin))

# here, I turned on annot and changed the color map scheme
ax = sns.heatmap(conf_mat, ax=ax, annot=True, cmap="cubehelix")
当我运行上面的代码时,它返回一个如下所示的数字

我希望带注释的数字适合热图的每个单元格,如果可能的话,颜色范围要合理一点(而不是现在所有的都是黑色)


如有任何改进建议,将不胜感激。谢谢。

您如何设想这些大数字来适应这些单元格<代码>15000将占用相当大的水平空间,因此所有单元格都需要宽约4倍。这就是你想要的吗?@hitzg是的。如果我想让电池宽4倍,我该怎么做?我是否将上述代码中的
矩阵\u高度\u pt
乘以
4
?谢谢你。@是的,我想那可能行得通。你试过了吗?@hitzg是的,我试过了……但没有成功。@user1330974你解决了这个问题吗?