在matplotlib中缩放图像而不更改轴

在matplotlib中缩放图像而不更改轴,第1张

在matplotlib中缩放图像而不更改轴

最后,我遵循了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


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5648799.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存