2 回答

TA貢獻1963條經(jīng)驗 獲得超6個贊
最后,我遵循了tcaswell的建議,并使用了2個不同的軸。這樣,我只需要使用set_xlim()和調(diào)整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
添加回答
舉報