python - 在 seaborn 中用科学记数法制作颜色条

标签 python pandas matplotlib seaborn

我正在 seaborn 中绘制以下热图。从下面读取数据帧。 csv 文件: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 中不行:

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})

enter image description here

关于python - 在 seaborn 中用科学记数法制作颜色条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35418989/

相关文章:

python - OpenCV-查找Canny边缘的轮廓

python - 在 python 中访问 HIDAPI 库

python - 在 python 中绘制 3d 数据的 2d 切片(最好使用 matplotlib)

python - 如何阻止 Matplotlib 导航工具栏缩放在绘图更新时重置?

python - 更改 3D 图形颜色 (matplotlib)

python - 为什么 sum() 和 min() 的 Python 内置函数要好得多?

python - 有什么方法可以使用 'nmap' 端口扫描器,在我的 Django 应用程序上生成和输出结果

python - 如何以相反的顺序在 pandas.core.groupby.DataFrameGroupBy 上使用 for 循环?

python - Python Pandas 的合并 (SQL) 功能

python - 如何创建 pandas "link"(href) 样式?