讓 sns.heatmap 的數字不使用科學計數法

搞來搞去,又是一小時,記錄一下
只需要增加 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)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章