Matplotlib Colorbar科学计数法偏移 [英] Matplotlib Colorbar scientific notation offset

查看:122
本文介绍了Matplotlib Colorbar科学计数法偏移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在绘制颜色条时,顶部标签(我想这将称为偏移)居中.这种情况以前没有发生过,我有一些旧代码的示例,它们位于颜色栏上方,但是我不知道发生了什么变化.

When plotting a colorbar, the top label (I guess this would be called the offset) is mis-centred. This didn't use to happen, I have examples of old code where it was centred above the colorbar, but I have no clue what has changed.

示例:

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

给出以下内容:

作为它过去外观的一个示例(摘自我的一篇旧论文,因此不同的数据等)

As an example of how it used to look (taken from one of my old papers, so different data etc.)

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

Using the most recent anaconda python 2.7, on MacOSX, mpl version 1.5.0

我还应该注意,tight_layout()也不能改善这一点,尽管工作示例中没有.

I should also note, tight_layout() does not improve this either, though it is missing from the working example.

推荐答案

您可以将 set_offset_position 用作颜色栏的y轴.比较:

You can simply use set_offset_position for the y-axis of the colorbar. Compare:

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

总而言之,看起来默认值从右移到了左.

All in all, it simply looks like the default has changed from right to left.

这篇关于Matplotlib Colorbar科学计数法偏移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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