使用 offsetbox 的颜色图范围

colormap range using offsetbox

如何在使用OffsetImage和AnnotationBbox时手动设置colormap范围?这些方法被调用如下(在我放置图像而不是 2D 点的循环内):

im = OffsetImage(img, zoom=zoom)
ab = AnnotationBbox(im, (x0, y0), xycoords='data', frameon=False)
artist.append(ax.add_artist(ab))

然后,在循环外:

ax.update_datalim(np.column_stack([x, y]))
ax.autoscale()

我正在将图像添加到ax中,我可以在OffsetImage中指定cmap,但是没有范围选项。如果我尝试

plt.clim(vmin, vmax)

发生错误:RuntimeError:找不到可用于创建颜色栏的可映射对象。

OffsetImage 将图像打包到 offsetbbox 中。所以,你需要得到 child: img = im.get_children()[0]; img.set_clim(vmin=0, vmax=3.14)