如何更改颜色条上基数和指数的字体大小?

时间:2015-12-03 03:11:18

标签: python matplotlib colorbar

enter image description here

我想更改base和exponent的大小以匹配我的colorbar上的ticks的fontsize。我怎么能这样做?

for i in xrange(col):

    plt.plot( t, x[i], color = s_m.to_rgba(slopes[i]), linewidth = 3 )


cbar = plt.colorbar(s_m)
cbar.formatter.set_powerlimits((0, 0))


cbar.update_ticks()

cbar.ax.tick_params(labelsize=20) 

1 个答案:

答案 0 :(得分:3)

首先,让我们拼凑一个独立的例子来展示你的问题。您已经更改了颜色条的刻度标签的大小,但偏移标签没有更新。例如,如果颜色条顶部的文本与刻度标签的大小匹配,那就太好了:

import numpy as np
import matplotlib.pyplot as plt

data = np.random.random((10, 10)) * 1e-6

fig, ax = plt.subplots()
im = ax.imshow(data)
cbar = fig.colorbar(im)

cbar.ax.tick_params(labelsize=20)
ax.set(xticks=[], yticks=[])

plt.show()

enter image description here

您想要更改的内容称为offset_text。在这种情况下,它是颜色条的y轴的偏移文本。你想做类似的事情:

cbar.ax.yaxis.get_offset_text.set(size=20)

cbar.ax.yaxis.offsetText.set(size=20)

作为一个完整的例子:

import numpy as np
import matplotlib.pyplot as plt

data = np.random.random((10, 10)) * 1e-6

fig, ax = plt.subplots()
im = ax.imshow(data)
cbar = fig.colorbar(im)

cbar.ax.tick_params(labelsize=20)
ax.set(xticks=[], yticks=[])

cbar.ax.yaxis.get_offset_text().set(size=20)

plt.show()

enter image description here