2 回答

TA贡献1963条经验 获得超6个赞
最后,我遵循了tcaswell的建议,并使用了2个不同的轴。这样,我只需要使用set_xlim()和调整set_ylim()图像轴,即可更改图像的原点和/或缩放比例。我想将图像隐藏在绘图下方,而不必将其与绘图框架一起隐藏,而是删除了绘图框架,并改用了图像轴框架。我还隐藏了图像轴上的刻度线。
from matplotlib import pyplot
f = pyplot.figure()
a = f.add_subplot(111, frameon=False) # Remove frame
a.plot(...)
myimg = pyplot.imread(...)
imgaxes = f.add_axes(a.get_position(), # new axes with same position
label='image', # label to ensure imgaxes is different from a
zorder=-1, # put image below the plot
xticks=[], yticks=[]) # remove the ticks
img = imgaxes.imshow(myimg, aspect='auto') # ensure image takes all the place
# now, to modify things
img.set_alpha(...)
imgaxes.set_xlim((x1, x2)) # x1 and x2 must be calculated from
# image size, origin, and zoom factor
添加回答
举报