粗体刻度标签 colorbar matplotlib

Bold ticklabels colorbar matplolib

为了使用 cartopy 在子图中保留颜色条方面,我在我的图中插入了新轴 (add_axes),但在添加时,我需要更改滴答标签颜色条和粗体的大小。但是 tick_params 和 set_yticklabels 在新轴上不起作用。

# pos x,  pos y, size x, size y
cb_ax = fig.add_axes([0.91, 0.302, 0.015, 0.383])

bar = fig.colorbar(img, cax=cb_ax, extend='max',
                   shrink=0.8, pad=0.0, spacing='uniform',
                   orientation='vertical', ticks=clevs,
                   extendfrac='auto')

bar.set_label(label=f'(mm)', size=10, weight='bold')

# not working
# bar.tick_params(labelsize=10)

# not working
# bar.img.set_yticklabels(clevs, fontsize=9, weight='bold')

完整代码:https://pastebin.com/NfiMWf2n

绘图结果:https://1drv.ms/u/s!Amb6LUmV4LnKi55gRf6DqGDKjfTGxA?e=HCGeZb

可以设置bar.ax的粗细和字体大小:

import matplotlib.pyplot as plt
import numpy as np
fig=plt.figure()
img = plt.imshow(np.random.random((4,4)))
cb_ax = fig.add_axes([0.91, 0.302, 0.015, 0.383])
bar = fig.colorbar(img, cax=cb_ax, extend='max',
                   shrink=0.8, pad=0.0, spacing='uniform',
                   orientation='vertical',
                   extendfrac='auto')
fig.canvas.flush_events() #else bar.ax.get_yticklabels() is not yet updated
bar.ax.set_yticklabels(labels=bar.ax.get_yticklabels(), weight='bold', fontsize=5)
bar.set_label(label=f'(mm)', size=10, weight='bold')

输出: