用seaborn制作带有科学记数法的颜色条 [英] making colorbar with scientific notation in seaborn

查看:81
本文介绍了用seaborn制作带有科学记数法的颜色条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用seaborn绘制以下热图.该数据帧是从foll读取的. csv文件: https://www.dropbox.com/s/mb3wc8mmis0m7g6/df_trans.csv?dl = 0

I am plotting the following heatmap in seaborn. the dataframe is read from the foll. csv file: https://www.dropbox.com/s/mb3wc8mmis0m7g6/df_trans.csv?dl=0

ax = sns.heatmap(df, linewidths=.1, linecolor='gray', cmap=sns.cubehelix_palette(light=1, as_cmap=True))
locs, labels = plt.xticks()
plt.setp(labels, rotation=0)
locs, labels = plt.yticks()
plt.setp(labels, rotation=0)

如何修改颜色条编号,使它们的160000显示为1.6,颜色条顶部为10 ^ 5.我知道在matplotlib中执行此操作很热,但在seaborn中却不行:

How can I modify the colorbar numbers so that they 160000 shows up as 1.6 with a 10^5 on top of colorbar. I know hot to do this in matplotlib but not in seaborn:

import matplotlib.ticker as tkr
formatter = tkr.ScalarFormatter(useMathText=True)
formatter.set_scientific(True)
ax.yaxis.set_major_formatter(formatter)

推荐答案

通过cbar_kws传递formatter对象:

import numpy as np
import seaborn as sns
import matplotlib.ticker as tkr

formatter = tkr.ScalarFormatter(useMathText=True)
formatter.set_scientific(True)
formatter.set_powerlimits((-2, 2))

x = np.exp(np.random.uniform(size=(10, 10)) * 10)
sns.heatmap(x, cbar_kws={"format": formatter})

这篇关于用seaborn制作带有科学记数法的颜色条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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