如何理解Seaborn的热图注释格式? [英] how to understand Seaborn's heatmap annotation format?

查看:47
本文介绍了如何理解Seaborn的热图注释格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法,通过指定 fmt 关键字,在 seaboarn 的热图上将0.0045"显示为0.45%":

I am looking for a way to show "0.0045" as "0.45%" on seaboarn's heatmap by specifying the fmt keyword:

sns.heatmap(data, annot=True, fmt='??')

但是,我没有找到要使用的格式列表.在不同的示例之间进行搜索,我看到了"d",.2g",.1f",.1f%".但不清楚我们在这里假设的约定是什么.

However, I did not find a list of format to use. Searching between different examples, I have seen "d", ".2g", ".1f", ".1f%". But it is not clear what is the convention we are assuming here.

这是假设人们对格式化格式有共同的理解吗?或者这出现在我错过的文档页面上?

Is this assuming people have a common understanding of the formatting format? Or this is present on a doc page I missed?

推荐答案

您可以将 .2%用作 fmt ,以将注释显示为百分比,并带有两位小数的地方.以下是一个最小的完整示例.我已经除以 100 以获得您感兴趣的范围内的数字

You can use .2% as the fmt to have your annotations displayed as percentages with 2 decimal places. Following is a minimum complete example. I have divided by 100 to have numbers in the range you are interested in

import numpy as np; np.random.seed(0)
import seaborn as sns; sns.set()
uniform_data = np.random.rand(6, 6)/100
ax = sns.heatmap(uniform_data,annot=True, fmt=".2%")

这篇关于如何理解Seaborn的热图注释格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆