Is It Possible To Patch An Image In Matplotlib?
I'm developing and automata in Python with matplotlib, and I would like to design it with a robot-look I picked on the web. I chose a file and I would like to place it in place of
Solution 1:
I don't believe patches are meant for this purpose. However, since you undoubtedly know the location and bounding area of the black boxes, OffsetImage and AnnotationBbox is a viable alternative.
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 inzip(x,y):
box = AnnotationBbox(oi, (px, py), frameon=False)
a.append(ax.add_artist(box))
ax.plot(x,y,'r--')
Hope this helps.
Post a Comment for "Is It Possible To Patch An Image In Matplotlib?"