彩条offsetText(科学基础乘数)从彩条的顶部移至底部 [英] Colorbar offsetText (scientific base multiplier) move from top to bottom of colorbar

查看:143
本文介绍了彩条offsetText(科学基础乘数)从彩条的顶部移至底部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里因为这个简单"问题而失去了智慧:

I'm losing my wits here with this 'simple' problem:

在matplotlib的颜色栏中(如图所示),我需要将offsetText(基本乘数)从颜色栏的顶部移到底部.

In the colorbar (illustrated in picture) in matplotlib I need to move offsetText (base multiplier) from top of the colorbar to bottom.

我用于此绘图的代码是(使用gridspec):

Code that I'm using for this plot is (using gridspec):

f.add_subplot(ax12)

ax10 = plt.Subplot(f, gs00[1, 0])
cb = plt.colorbar(h3,cax=ax10)
cb.formatter.set_scientific(True)
cb.formatter.set_powerlimits((0,0))
cb.ax.yaxis.offsetText.set(size=6)
cb.update_ticks()

ax10.yaxis.set_ticks_position('left')
ax10.tick_params(labelsize=6)
f.add_subplot(ax10)

提前谢谢! (顺便说一句,Python版本= 2.7.6,matplotlib版本= 1.3.1-在我完成当前项目之前,当前无法升级)

Thanks in advance! (Btw, Python version = 2.7.6, matplotlib version = 1.3.1 - upgrading currently not an option until I finish current project)

推荐答案

通常无法更改offsetText标签的位置.这仍然是未解决的问题.

It's in general not possible to change the position of the offsetText label. This would still be an open issue.

为此,可以有一个解决方案来覆盖yaxis的_update_offset_text_position方法,将offsetText放置在yaxis的底部.

A solution can therefor be to overwrite the yaxis' _update_offset_text_position method to position the offsetText on the bottom of the yaxis.

import matplotlib.pyplot as plt
import types

def bottom_offset(self, bboxes, bboxes2):
    bottom = self.axes.bbox.ymin
    self.offsetText.set(va="top", ha="left")
    self.offsetText.set_position(
            (0, bottom - self.OFFSETTEXTPAD * self.figure.dpi / 72.0))

fig, ax = plt.subplots()
im = ax.imshow([[1e5,2e5],[0.1e5,1e5]])
cb = plt.colorbar(im)
cb.formatter.set_scientific(True)
cb.formatter.set_powerlimits((0,0))

def register_bottom_offset(axis, func):
    axis._update_offset_text_position = types.MethodType(func, axis)
register_bottom_offset(cb.ax.yaxis, bottom_offset)

cb.update_ticks()

plt.show()

如果颜色栏位于图的左侧,则下面的外观可能会更好:

If the colorbar is positioned on the left side of the plot the following might look better:

self.offsetText.set(va="top", ha="right")
self.offsetText.set_position(
            (1, bottom - self.OFFSETTEXTPAD * self.figure.dpi / 72.0))

这篇关于彩条offsetText(科学基础乘数)从彩条的顶部移至底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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