搞来搞去,又是一小时,记录一下
只需要增加 fmt 参数即可
sns.heatmap(cm, annot=True, fmt='.20g', cmap=plt.cm.Blues)
完整例子,先显示默认的,再使用去掉科学计数法的
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
cm = np.random.randint(0, 30000, [4, 4])
# 默认 fmt 参数
f = plt.figure(1, clear=True)
sns.heatmap(cm, annot=True, cmap=plt.cm.Blues)
f.show()
# plt.pause(5)
# 修改后 fmt 参数
f = plt.figure(2, clear=True)
sns.heatmap(cm, annot=True, fmt='.20g', cmap=plt.cm.Blues)
f.show()
plt.pause(5)
本文介绍如何在Seaborn库中使用热力图(heatmap)时,优化数值显示格式,避免科学计数法,通过调整fmt参数实现更直观的数据呈现。
1万+

被折叠的 条评论
为什么被折叠?



