gpt4 book ai didi

python - Matplotlib Colorbar 科学记数法偏移量

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

绘制颜色条时,顶部标签(我想这将称为偏移量)居中错误。这在过去不会发生,我有旧代码的示例,它位于颜色条上方的中心,但我不知道发生了什么变化。

例子:

import numpy as np
import matplotlib.pyplot as plt

z = np.random.random((10,10))

fig, ax = plt.subplots()
im = ax.imshow(z)
cb = fig.colorbar(im)

cb.formatter.set_powerlimits((0, 0))
cb.update_ticks()

plt.show()

给出这个:

Offset colorbar notation

作为它过去的样子的例子(取 self 的一篇旧论文,所以不同的数据等)

Proper colorbar notation

在 MacOSX 上使用最新的 anaconda python 2.7,mpl 版本 1.5.0

编辑:我还应该注意,tight_layout() 也没有改善这一点,尽管工作示例中缺少它。

最佳答案

您可以简单地使用 set_offset_position 作为颜色条的 y 轴。比较:

fig, ax = plt.subplots()                
im = ax.imshow(np.random.random((10,10)))
cb = fig.colorbar(im)
cb.formatter.set_powerlimits((0, 0))
cb.ax.yaxis.set_offset_position('right')
cb.update_ticks()
plt.show()

enter image description here

对比

fig, ax = plt.subplots()
im = ax.imshow(np.random.random((10,10)))
cb = fig.colorbar(im)
cb.formatter.set_powerlimits((0, 0))
cb.ax.yaxis.set_offset_position('left')
cb.update_ticks()
plt.show()

enter image description here

总而言之,看起来默认值已从右变为左。

关于python - Matplotlib Colorbar 科学记数法偏移量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34039396/

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