绘制颜色条时,顶部标签(我想这将称为偏移量)居中错误。这在过去不会发生,我有旧代码的示例,它位于颜色条上方的中心,但我不知道发生了什么变化。
例子:
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()
给出这个:
作为它过去的样子的例子(取 self 的一篇旧论文,所以不同的数据等)
在 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()
对比
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()
总而言之,看起来默认值已从右变为左。
我是一名优秀的程序员,十分优秀!