四舍五入的小数点seaborn热图标签

时间:2020-09-18 23:44:40

标签: python-3.x matplotlib seaborn heatmap

我有一个自动获取标签的热图,但是其中一些是长十进制(我不明白为什么,因为我用于热图的值有3个小数,例如0.009表示为长十进制),我想将所有标签四舍五入到小数点后四位。这是代码的相关部分:

table1 = df.pivot('ToxinK','Khill','Fraction') #Putting information from the dataframe into a pivot table
sns.heatmap(table1,cmap='Purples',norm=LogNorm())

enter image description here

我尝试了在seaborn too long numeric labels上找到的解决方案,但是不适用于我,我不知道为什么 这是尝试:

majorFormatter = FormatStrFormatter('%0.4f')
ax1=sns.heatmap(table1,cmap='Purples',norm=LogNorm())
ax1.yaxis.set_major_formatter(majorFormatter)

enter image description here

关于如何解决此问题的任何建议或信息将非常有用。预先感谢!

1 个答案:

答案 0 :(得分:0)

要格式化注释,请输入参数 fmt='.4f' 以保留 4 位小数。 以您的第一个代码为例:

sns.heatmap(table1, cmap='Purples', fmt='.4f')
相关问题