最后,我遵循了tcaswell的建议,并使用了2个不同的轴。这样,我只需要使用
set_xlim()和调整
set_ylim()图像轴,即可更改图像的原点和/或缩放比例。我要获得图的下方的图像,而不用图的框架隐藏它,而是删除了图的框架,改用图像轴的框架。我还隐藏了图像轴上的刻度线。
from matplotlib import pyplotf = pyplot.figure()a = f.add_subplot(111, frameon=False) # Remove framea.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 ticksimg = imgaxes.imshow(myimg, aspect='auto') # ensure image takes all the place# now, to modify thingsimg.set_alpha(...)imgaxes.set_xlim((x1, x2)) # x1 and x2 must be calculated from # image size, origin, and zoom factor
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)