在 Seaborn 中为热图批注添加单位


要向 Seaborn 中的热图批注添加单位,我们可以采取以下步骤 -

  • 设置图表大小并调整子图之间和周围的边距。

  • 使用 numpy 创建一个 5×5 维度矩阵。

  • 以颜色编码矩阵的形式绘制矩形数据。

  • %age 单位注释热图值。

  • 要显示图表,使用 show() 方法。

示例

import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np

plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True

data = np.random.rand(5, 5)

ax = sns.heatmap(data, annot=True, fmt='.1f', square=1, linewidth=1.)

for t in ax.texts: t.set_text(t.get_text() + " %")

plt.show()

输出

更新于: 04-6 月 -2021

537 次浏览

拉开你的 职业生涯

通过完成课程获得认证

开始
广告
© . All rights reserved.