Home > OS >  Using an image as a matplotlib marker and drawing a circle around that marker
Using an image as a matplotlib marker and drawing a circle around that marker

Time:12-28

I was using an image as a matplotlib marker , I have attached the code below


import matplotlib.pyplot as plt 
from matplotlib import patches 
from matplotlib.offsetbox import OffsetImage, AnnotationBbox
import random

plt.rcParams["figure.figsize"] = [10.0,10.0]
plt.rcParams["figure.autolayout"] = True

def getImage(path):
   return OffsetImage(plt.imread(path, format="png"), zoom=.1)

paths = ['BS.png']
for i in range(49):
    paths.append('BS.png',)
#print(paths)

x = []
for i in range(50):
    x.append(random.randint(0,10))
print(x)

y = []
for i in range(50):
    y.append(random.randint(0,10))   
print(y)

fig, ax = plt.subplots()
circle1 = patches.Circle((5, 5), radius=20, fill = False ,edgecolor = 'black')
for x0,y0,path in zip(x, y, paths):
    ab = AnnotationBbox(getImage(path), (x0, y0), frameon=False)
    ax.add_artist(ab)
plt.xticks(range(10))
plt.yticks(range(10))
ax.axis('off')

plt.show()

output

  • Related