gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 12:46:05 25 4
gpt4 key购买 nike

我正在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com