python - 是否可以在 matplotlib 中修补图像?

标签 python matplotlib

我正在使用 matplotlib 在 Python 中开发和自动机,我想用我在网络上选择的机器人外观来设计它。我选择了一个文件,我想将其放置在下图中黑色方 block 的位置...

enter image description here

我一直在网上寻找一种方法,但没有找到任何答案。 仅供引用,我使用 fig = plt.Figure() 方法,然后使用 fig.add_subplot 创建子图,最后通过创建黑色补丁生成黑色方 block 。

最佳答案

我不认为补丁是用于此目的的。然而,由于您无疑知道黑框的位置和边界区域,OffsetImage 和 AnnotationBbox 是一个可行的替代方案。

import math
import numpy as np
from matplotlib.offsetbox import OffsetImage, AnnotationBbox

x = np.linspace(0,10, 10)
y = [math.sin(i) for i in x]
fig, ax = plt.subplots()
im = plt.imread('pacman.png')
oi = OffsetImage(im, zoom = 0.15)
a = []
for px, py in zip(x,y):
    box = AnnotationBbox(oi, (px, py), frameon=False)
    a.append(ax.add_artist(box))
ax.plot(x,y,'r--')

enter image description here

希望这有帮助。

关于python - 是否可以在 matplotlib 中修补图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41453902/

相关文章:

python - opencv imshow()函数现在有按钮了吗?

python - matplotlib散点图在x轴上改变距离

python - 如何将垂直和水平轴标签设置为粗体或字体

python - 如何在 matplotlib 中更改 x 轴和 y 轴?

python - 散点图标签重叠-Matplotlib

Python/pylint E1101 需要有关正确对象定义的帮助

python - 如果值与字典映射不匹配,如何从数据框行中删除它?

Python Pandas sizeof 倍

Python:循环中的del

python - 如何在使用 ax.axis ('equal' 时强制执行 xlim 和 ylim )?